【发布时间】:2019-09-28 12:54:29
【问题描述】:
我的 Spring 微服务原型应用程序无法启动并显示以下消息:
***************************
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
应用依赖如下:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.security:spring-security-test'
}
我假设 data-jpa 和 h2 都带有数据源。我之前有过类似的组合,没有这个问题。我想可以通过在依赖项之一中排除数据源来解决问题。经过网上搜索,我没有找到它是如何工作的。
有什么建议吗?
【问题讨论】:
-
您使用的是 Spring Boot 2.1 和不兼容的 Spring Cloud 版本吗?见stackoverflow.com/questions/53104697/…。
-
对我来说,这是因为我的 Spring Boot 启动器使用了不正确的 Spring Cloud 版本 --> 对于 Spring 2.2.4 从 Spring Cloud 版本 Finchley.Release 到 Hoxton.Release 为我解决了这个问题跨度>