创建名为“appConfig”的bean时发生java错误:合并bean定义的后处理失败;
我正在集成项目2和项目1(maven项目)。项目2测试没有开始,因为 创建名为“appConfig”的bean时出错:合并bean定义的后处理失败
详情:
项目1:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.0.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.13.Final</version>
</dependency>
项目2依赖项:
<properties>
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
在project 1 pom中添加依赖项之后。xml
测试跑步者:
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class, initializers = {
ConfigFileApplicationContextInitializer.class })
我的Junit测试根本没有启动,下面是错误: 创建名为“appConfig”的bean时出错:合并bean定义的后处理失败
我无法更改或删除Project 1依赖项。我可以在project 2中更改依赖项和版本
谷歌——一些解决方案说,spring的依赖性导致了这个问题。但我无法修复它
请帮忙。提前谢谢你
# 1 楼答案
首先,你的依赖关系一团糟。您正在混合至少不同版本的Spring和Spring Boot。千万不要混用来自不同版本框架的JAR,因为这是一个等待发生的麻烦
删除
spring-context
、spring-core
和spring-web
依赖项,它们是启动程序的一部分。从Spring Boot Starter中删除<version />
标记(假设您使用Spring Boot Starter父级作为父级,否则将实际版本替换为${spring-boot.version}
以使用一致的版本控制