maven包冲突及解决思路

maven包冲突

前情提要:原项目为spring项目,现需要改为Springboot项目。将pom依赖copy过来后报错如下:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$AutoConfiguredAnnotationRepositoryConfigurationSource.<init>(AbstractRepositoryConfigurationSourceSupport.java:133)

The following method did not exist:

    org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;Lorg/springframework/beans/factory/support/BeanNameGenerator;)V

The method's class, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource, is available from the following locations:

    jar:file:/D:/DevelopSoftWare/maven_rely_jar/org/springframework/data/spring-data-commons/1.13.4.RELEASE/spring-data-commons-1.13.4.RELEASE.jar!/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSource.class

The class hierarchy was loaded from the following locations:

    org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource: file:/D:/DevelopSoftWare/maven_rely_jar/org/springframework/data/spring-data-commons/1.13.4.RELEASE/spring-data-commons-1.13.4.RELEASE.jar
    org.springframework.data.repository.config.RepositoryConfigurationSourceSupport: file:/D:/DevelopSoftWare/maven_rely_jar/org/springframework/data/spring-data-commons/1.13.4.RELEASE/spring-data-commons-1.13.4.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource

Disconnected from the target VM, address: '127.0.0.1:58560', transport: 'socket'

Process finished with exit code 1

看异常是包有问题,发现spring-data-commons/1.13.4.RELEASE出现了多次,那么复制spring-data-commons到pom文件夹里面去找。

MongoDB.png

找到是mongoDb包的问题。想到是springboot项目,原来以前的spring项目的mongoDB引入包应该改为xxxStarter,遂将pom依赖改为如下引入

  <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-mongodb</artifactId>
                <version>2.3.2.RELEASE</version>
                <exclusions>
                    <exclusion>
                        <artifactId>spring-data-mongodb</artifactId>
                        <groupId>org.springframework.data</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-mongodb</artifactId>
                <version>3.0.3.RELEASE</version>
            </dependency>-

问题解决。

乍一看不知道怎么解决,如果百度无法给你答案,先猜,然后根据关键字搜索。解决问题后记录。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容