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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring-Boot:錯誤注入多個bean

Spring-Boot:錯誤注入多個bean

慕村225694 2023-08-04 15:26:50
我正在嘗試讓應(yīng)用程序在 Spring-boot 中工作,但遇到注入錯誤。我有一個帶有一些@Autowire 類的@Service。我們的類只是帶有一個public setDatSource方法的 POJO,我需要通過運(yùn)行時設(shè)置數(shù)據(jù)源。見下文:    @Bean    @Qualifier("datasetDao")    public com.lexi.dao.core.DatasetDAO getDatasetDao() throws NamingException {        DatasetDAOImpl ds = new DatasetDAOImpl();        ds.setDataSource(createAuthReadDataSoure());        return ds;    }    @Bean    public LicenseDAO getLicenseDao() throws NamingException {        LicenseDAOImpl ds = new LicenseDAOImpl();        ds.setReadDataSource(createOnlineDSReadDataSoure());        ds.setWriteDataSource(createOnlineDSWriteDataSoure());        ds.setDistribDataSource(createAuthReadDataSoure());        return ds;    }我有一個服務(wù)定義如下:@Servicepublic class LicenseService {    @Autowired    @Qualifier("datasetDao")    private DatasetDAO datasetDao;    @Autowired    private LicenseDAO licenseDao;但是,當(dāng)我運(yùn)行該應(yīng)用程序時,我得到以下信息:***************************APPLICATION FAILED TO START***************************Description:Field datasetDao in com.wk.online.services.LicenseService required a single bean, but 3 were found:    - createAuthReadDataSoure: defined by method 'createAuthReadDataSoure' in com.wk.online.ws.OnlineWsApplication    - createOnlineDSReadDataSoure: defined by method 'createOnlineDSReadDataSoure' in com.wk.online.ws.OnlineWsApplication    - createOnlineDSWriteDataSoure: defined by method 'createOnlineDSWriteDataSoure' in com.wk.online.ws.OnlineWsApplicationAction:Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed我嘗試添加一個@Qualifier,但這似乎與Spring 不一致。我錯過了什么,我已經(jīng)這樣做了一段時間,并認(rèn)為我正在做一些非常愚蠢的事情。
查看完整描述

3 回答

?
holdtom

TA貢獻(xiàn)1805條經(jīng)驗 獲得超10個贊

定義 bean 時,您需要指定名稱,而不是限定符,應(yīng)在自動裝配它的地方使用限定符注釋:


@Bean(name = "datasetDao")

public com.lexi.dao.core.DatasetDAO getDatasetDao() throws NamingException {

    DatasetDAOImpl ds = new DatasetDAOImpl();

    ds.setDataSource(createAuthReadDataSoure());


    return ds;

}


查看完整回答
反對 回復(fù) 2023-08-04
?
白衣非少年

TA貢獻(xiàn)1155條經(jīng)驗 獲得超0個贊

您在類@Bean中對以下方法有注釋嗎?OnlineWsApplication

  • createAuthReadDataSoure

  • createOnlineDSReadDataSoure

  • createOnlineDSWriteDataSoure

如果是的話,擺脫它們。

完整的代碼OnlineWsApplication對于入侵它非常有用。


查看完整回答
反對 回復(fù) 2023-08-04
?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗 獲得超7個贊

在bean定義中,用@Qualifier("datasetDao")代替@Bean

嘗試使用以下內(nèi)容:@Bean(name="datasetDao")


查看完整回答
反對 回復(fù) 2023-08-04
  • 3 回答
  • 0 關(guān)注
  • 244 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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