java解决包依赖冲突

后端报错如下:

WARN  [] o.s.b.t.j.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer.logDuplicateJsonObjectsWarning - 

Found multiple occurrences of org.json.JSONObject on the class path:

	jar:file:/D:/java_code/maven/repository/org/json/json/20140107/json-20140107.jar!/org/json/JSONObject.class
	jar:file:/D:/java_code/maven/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class

You may wish to exclude one of them to ensure predictable runtime behavior

即:有2个地方冲突的 json 依赖,需要 排除(exclude )一个。
解决办法:
下面那个 json-20140107.jar添加的json依赖希望保留,那么就需要排除掉 android-json 这个依赖。

首先需要知道这个 android-json 是在哪个依赖里面,pom.xml 直接搜肯定是找不到 android-json的。
寻找看不到的 依赖 android-json,在pom文件编辑页面,右键–Diagrams-Show Dependencies…
java解决包依赖冲突_第1张图片
java解决包依赖冲突_第2张图片
放大后(百度查看其他人ctrl+F可以进行搜索,本人尝试未能出现搜索框),找到android-json,根据依赖线箭头发现 android-json 在 spring-boot-starter-test 里面。

然后,在 spring-boot-starter-test 里面排除依赖 android-json ,如下:

   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
           <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

其实,就是在原有依赖里面加入了下面内容:

    >
                >
                    >com.vaadin.external.google>
                    >android-json>
                >
    >

类似的方法,解决一些隐藏的依赖包冲突 也可以这样去寻找解决!

你可能感兴趣的:(问题解决)