spring中在私有變量和構造方法上使用@aware報錯,在setter方法上就沒有報錯。
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
2017-12-02
在私有變量上 或者 setter方法上@autowired,如果程序中還有自己自行撰寫的構造函數,就會報錯
因為如果自行撰寫了構造函數,編譯程序就不會自動建立默認構造函數,所以會初始化失敗
2017-06-15
下圖調用了該類的默認構造器,不會報錯
下圖調用了自己重寫的構造器不會報錯。
下圖重寫構造器沒有使用注釋,set方法無法去找到bean
2016-07-21
No default constructor found;
setter設置注入就是調用setXXX方法,但是需要保留默認構造方法