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