springboot多數據源啟動報錯:required a single bean, but 6 were found:


技術群: 816227112

參考:https://stackoverflow.com/questions/43455869/could-not-autowire-there-is-more-than-one-bean-of-datasource-type

Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required a single bean, but 6 were found:
    - agencyConnectionFactory: defined by method 'agencyConnectionFactory' in class path resource [com/sinosoft/config/RedisConfig.class]
    - cellConnectionFactory: defined by method 'cellConnectionFactory' in class path resource [com/sinosoft/config/RedisConfig.class]
    - mipConnectionFactory: defined by method 'mipConnectionFactory' in class path resource [com/sinosoft/config/RedisConfig.class]
    - wechatConnectionFactory: defined by method 'wechatConnectionFactory' in class path resource [com/sinosoft/config/RedisConfig.class]
    - ybtbConnectionFactory: defined by method 'ybtbConnectionFactory' in class path resource [com/sinosoft/config/RedisConfig.class]
    - ybtgConnectionFactory: defined by method 'ybtgConnectionFactory' in class path resource [com/sinosoft/config/RedisConfig.class]

除了這種還有配置數據庫多數據源也會出現這種情況。

解決:

報錯的某一個配置上加上@Primary


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM