Caused by:
java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
<aop:config> <aop:aspect ref="indexService"> <aop:pointcut id="generateTopPoint" expression="execution(* com.lj.cms.service.ChannelService.add*(..))|| execution(* com.lj.cms.service.ChannelService.delete*(..))|| execution(* com.lj.cms.service.ChannelService.update*(..))"/> <aop:after method="generateTop" pointcut-ref="generateTopPoint"/> </aop:aspect> </aop:config> <bean id="ftlPath" class="java.lang.String"> <constructor-arg value="/ftl"></constructor-arg> </bean> <bean id="outPath" class="java.lang.String"> <constructor-arg value="/jsp/template"></constructor-arg> </bean> @Autowired(required=true) public IndexService(String ftlPath,String outPath) { if(util==null){ this.outPath = outPath; util=FreemarkerUtil.getInstance(ftlPath);//ftlPath在beans.xml中配置了依赖注入,值为/ftl } }
上述代码原本运行时是没有错误的。
后来因为需求把 <aop:config> 的内容去掉了。
结果就一直报如上错误。
弄了半天, 最后在stackoverflow上找到原因:
http://stackoverflow.com/questions/13711347/spring-constructor-dependency-injection-issues
Classes to be proxied by CGLIB (for AOP support) must have no-args constructors.
These no-args constructors don't have to be public and it doesn't affect anything else - you can use other constructors as usually:
因此只要加入
public IndexService() { }
问题就解决了。