首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解析“在类路径资源中定义的BeanDefinition中定义的bean 'dataSource‘”?

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

Stack Overflow用户
提问于 2019-05-10 23:22:11
回答 1查看 2.1K关注 0票数 0

我的Spring微服务原型应用程序无法启动,出现以下消息:

代码语言:javascript
复制
***************************
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

应用依赖关系如下:

代码语言:javascript
复制
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都带有数据源。我以前有过一个类似的组合,但没有这个问题。我猜这个问题可以通过排除其中一个依赖项中的数据源来解决。经过一些在线搜索,我还没有发现它是如何工作的。

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-10 23:55:53

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

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56080561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档