Justonedayzhupeng
2016-07-21 16:52
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'injectionServiceImpl' defined in file [E:\myexlipseworkspace\Spring2\bin\injectionannotation\InjectionServiceImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [injectionannotation.InjectionServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: injectionannotation.InjectionServiceImpl.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.spr
在私有变量上 或者 setter方法上@autowired,如果程序中还有自己自行撰写的构造函数,就会报错
因为如果自行撰写了构造函数,编译程序就不会自动建立默认构造函数,所以会初始化失败
下图调用了该类的默认构造器,不会报错
下图调用了自己重写的构造器不会报错。
下图重写构造器没有使用注释,set方法无法去找到bean
No default constructor found;
setter设置注入就是调用setXXX方法,但是需要保留默认构造方法
Spring入门篇
268787 学习 · 963 问题
相似问题