java - 创建名为“appConfig”的 bean 时出错:合并 bean 定义的后处理失败;
问题描述
我正在将项目 2 与项目 1(maven 项目)集成。项目 2 测试没有开始,因为创建名为“appConfig”的 bean 时出错:合并 bean 定义的后处理失败;
细节:
项目一:
<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>
在项目 1 pom.xml 中添加我的依赖项后
测试赛跑者:
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class, initializers = {
ConfigFileApplicationContextInitializer.class })
我的 Junit 测试根本没有开始,下面是错误:创建名为“appConfig”的 bean 时出错:合并 bean 定义的后处理失败;
我无法更改项目 1 的依赖项或删除它们。我可以更改项目 2 中的依赖项和版本。
谷歌搜索 - 一些解决方案说弹簧依赖导致问题。但我无法修复它
请帮助。在此先感谢您。
解决方案
对于初学者来说,你的依赖是一团糟。您至少混合了不同版本的 Spring 和 Spring Boot。永远不要混合来自不同版本的框架的 jar,因为那是等待发生的麻烦。
删除spring-context
,spring-core
和spring-web
依赖项,它们是启动器的一部分。从 Spring Boot 启动器中删除<version />
标记(假设您使用 Spring Boot Starter Parent 作为父级,否则将实际版本替换${spring-boot.version}
为使用一致的版本控制。
推荐阅读
- aframe - Aframe:物理+动画
- reactjs - 网格和蚂蚁设计
- python - 输入矩阵的值后无法跳出 while 循环
- javascript - React:如何在事件发生时获取新日期
- android - 如何在 android 中创建如下图所示的布局以及 android 布局中的 alpha 是什么
- ruby-on-rails - 如何在 Rails 5 中全面诊断测试环境问题
- javascript - 如何使用jQuery将html表单数据插入到html表格中?
- asp.net-core - IdentityServer4 与 AspNetIdentity。如何让 WebApi 访问 UserDb
- java - 使用 itext 时出错
- html - 如何使用纯 CSS 创建带有虚线的票形状?