`

Superclass has no null constructors but no arguments were given

阅读更多

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexService' defined in file [D:\konghaoShopping\cms-web\target\classes\com\lj\cms\service\IndexService.class]: Initialization of bean failed; nested exception is 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:
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
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:217)


Caused by:
java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given



这里是由于我在写service的时候自定义了一个constructor,而beans.xml中并没有配置对应的依赖注入。
spring要用无参构造函数,但是不能调用。

@Service("indexService")
public class IndexService implements IIndexService{
@Autowired(required=true)
	public IndexService(String ftlPath,String outPath)
	{
		super();
		this.ftlPath=ftlPath;
		this.outPath = outPath;
		
	}
}


解决方法只要在beans.xml中配置一下对应的依赖注入即可:

<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>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics