2016-01-21 39 views
-3

Pom.xml有这个元素,我很好奇为什么我们需要排除commons-loggingspring-core?它是如何工作的?为什么我们需要排除在pom

<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>3.0.5.RELEASE</version> 
     <type>jar</type> 
     <scope>compile</scope> 
     <exclusions> 
      <exclusion> 
       <artifactId>commons-logging</artifactId> 
       <groupId>commons-logging</groupId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
<!-- next is log4j dependencie --> 

回答

0

我所看到的和以前做过类似的事情,原因很简单:

要排除commons-logging库,因为我想用log4j代替。

所以,你告诉maven不包括不必要的库,并使用<exclusion>

0

您的程序中可能使用的版本不是commons-logging,而是由spring-core 3.0.5.RELEASE定义的版本。检查程序的依赖关系,看看是否有另外的commons-logging定义。

0

在上面的例子中,spring-core本身依赖于commons-logging,因此它会将该jar拖入项目中。出于什么原因,用户不想使用Spring-Core附带的commons-logging,他们可能想要使用另一个版本。

可能有2个依赖关系,它们之间存在相互依赖关系,尽管我会说这很少见。通常排除可以谨慎使用。