一、问题描述
在SpringBoot下使用Junit4进行单元测试,出现了Found multiple occurrences of org.json.JSONObject on the class path:
jar:file:/D:/apache-maven-3.3.9/maven-repository/org/json/json/20160810/json-20160810.jar!/org/json/JSONObject.class
jar:file:/D:/apache-maven-3.3.9/maven-repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class
二、 解决方案
在maven依赖中排除
<!-- 单元测试-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
三、spring boot 框架的Bug
github地址: https://github.com/spring-projects/spring-boot/issues/9630
本文详细介绍了在SpringBoot项目中使用Junit4进行单元测试时遇到的JSON冲突问题,特别是多个不同版本的org.json.JSONObject类同时存在于类路径上导致的问题。文章提供了具体的解决方案,即通过在Maven依赖中排除特定的android-json依赖来解决冲突。
1138

被折叠的 条评论
为什么被折叠?



