当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

Superclass has no null constructors but no arguments were given

发表于: 2014-03-28   作者:alleni123   来源:转载   浏览:
摘要: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lj.cms.service.IndexService]: Common causes of this problem include using a final class or a
org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lj.cms.service.IndexService]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given


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()
{
}


问题就解决了。

Superclass has no null constructors but no arguments were given

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号