maven 依赖管理原则

参考maven-两大依赖原则 - SegmentFault 思否

在开发中,我们可能会出现一个项目存在多个相同版本不同的jar包,在这个时候我们就需要解决maven包冲突的问题(常见的异常有:Class not found,Method not found,calss not defined, NoSuchFiled等)

1,路径近者优先级高

2,节点路径相同时,,使用第一声明优先(也就是谁在pom.xml文件前面谁优先)

3,以上都不能解决,我们就用直接排除法,如下

<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.2.4.RELEASE</version>
            <!--直接排除-->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.2.RELEASE</version>
        </dependency>

    </dependencies>

我们没有直接排除之前,我们发现我们使用的时spring-core4.2.4,排除后是使用的5.0.2

posted @ 2021-08-27 01:33  在线电影制作人  阅读(6)  评论(0)    收藏  举报  来源