第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

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


正在回答

3 回答

在私有變量上 或者 setter方法上@autowired,如果程序中還有自己自行撰寫的構(gòu)造函數(shù),就會報錯

因為如果自行撰寫了構(gòu)造函數(shù),編譯程序就不會自動建立默認(rèn)構(gòu)造函數(shù),所以會初始化失敗

0 回復(fù) 有任何疑惑可以回復(fù)我~

下圖調(diào)用了該類的默認(rèn)構(gòu)造器,不會報錯

http://img1.sycdn.imooc.com//59423e8d0001a11906760559.jpg

下圖調(diào)用了自己重寫的構(gòu)造器不會報錯。

http://img1.sycdn.imooc.com//59423e8e00011ba506480557.jpg

http://img1.sycdn.imooc.com//59423e8f0001131607900563.jpg

下圖重寫構(gòu)造器沒有使用注釋,set方法無法去找到bean

http://img1.sycdn.imooc.com//59423e9100010ec807030564.jpg


1 回復(fù) 有任何疑惑可以回復(fù)我~

No default constructor found;

setter設(shè)置注入就是調(diào)用setXXX方法,但是需要保留默認(rèn)構(gòu)造方法

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

spring中在私有變量和構(gòu)造方法上使用@aware報錯,在setter方法上就沒有報錯。

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號