報錯信息
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2020-09-17 16:34:52.056 ERROR 19128 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
The bean ‘dataSource’, defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class],could not beregistered. A bean with that name hasal ready been defined in classpath resource[org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class],could not beregistered. A bean with that name hasal ready been defined in classpath resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Disconnected from the target VM, address: ‘127.0.0.1:62029’, transport: ‘socket’
Process finished with exit code 1
————————————————
從錯誤信息中可以看到,dataSource這個bean已經被register(注冊)了。
解決方法
配置文件中加入如下配置
# 設置為true時,后定義的bean會覆蓋之前定義的相同名稱的bean
spring.main.allow-bean-definition-overriding=true
#注:spring中默認是true,也就是默認支持名稱相同的bean的覆蓋。而springboot中的默認值是false,也就是不支持名稱相同的bean被覆蓋。
根本原因分析
終究原因后面發現是SpringBoot和SpringCloud版本匹配問題導致的;把版本降下來后,問題自然解決了,這才是推薦方案,從根本上解決。
文章轉載至:https://blog.csdn.net/weixin_39098944/article/details/108647058