1:spring版本冲突:在使用maven时有可能会意外的混入了不同版本的spring jar包,比如你可能会发现第三方库,或者另外一个spring project,如果你忘了明确地声明依赖,会出现各种意想不到的事情。为了克服这样的问题,maven提供了 "bill of materials" (BOM) 依赖的理念,你可以在你的dependencyManagement
部分导入spring-framework-bom,所有spring依赖(直接和传递的)都是相同的版本。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.3.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
使用BOM一个额外的好处是在依赖spring framework artifact时你不在需要指定<version>属性
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependencies>
2:日志版本冲突:运行时查找common-logging的算法,在方便最终用户的同时,也会出现问题。如果时间可以回退将spring作为新的项目开始,将会使用不同的日志依赖,首要的选择就是Simple Logging Facade for Java ( SLF4J)。
这有两条基本的方式关闭common-logging:
(1)从spring-core中排除common-logging依赖,
(2)依赖特殊的common-logging,用空jar文件替代库
排除common-logging,在你的dependencyManagement
添加以下代码:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.3.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
使用SLF4J:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.3.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
多个slf4j,可选的。