如何解决"The bean 'dataSource', defined in BeanDefinition defined in class path resource"?
How to resolve "The bean 'dataSource', defined in BeanDefinition defined in class path resource"?
我的 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 都带有数据源。我以前有过类似的组合,没有这个问题。我想这个问题可以通过在其中一个依赖项中排除数据源来解决。上网查了一下,没找到具体的操作方法。
有什么建议吗?
您可以将以下内容添加到主 class:
@EnableAutoConfiguration(排除={DataSourceAutoConfiguration.class})
我的 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 都带有数据源。我以前有过类似的组合,没有这个问题。我想这个问题可以通过在其中一个依赖项中排除数据源来解决。上网查了一下,没找到具体的操作方法。
有什么建议吗?
您可以将以下内容添加到主 class:
@EnableAutoConfiguration(排除={DataSourceAutoConfiguration.class})