1. 程式人生 > >A bean with that name has already been defined in DataSourceConfiguration$Hikari.class

A bean with that name has already been defined in DataSourceConfiguration$Hikari.class

問題:

啟動SpringBoot專案報錯:

***************************
APPLICATION FAILED TO START
***************************
Description:

The bean 'dataSource', defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

原因:

SpringBoot和SpringCloud的版本不相容造成。
這裡因為SpringBoot想嚐鮮使用了2.1.0,而SpringCloud仍然用的是Finchley.SR2,而它支援的是2.0.x及以下版本。
對應的版本應該使用Greenwich.M1
Issues回答:
在這裡插入圖片描述
在這裡插入圖片描述

解決:

降SpringBoot版本或者使用Greenwich.M1
所以還是建議直接在start.spring.io上構建新專案,或者在idea上構建專案的時候選擇Spring Initializr來避免版本不相容。