如何解决“在类路径资源中定义的BeanDefinition中定义的bean'dataSource'”?

时间:2019-05-10 15:22:11

标签: spring-boot spring-cloud

我的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都带有数据源。在没有这个问题之前,我也有类似的组合。我猜想可以通过在依赖项之一中排除数据源来解决该问题。经过一些在线搜索后,我还没有发现它是如何工作的。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您可以在主类中添加以下内容:

@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})