2017-07-07 155 views
0

我使用Spring 1.4.0引導和彈簧雲偵探,這裏是我的POM:春季雲偵探+春季啓動1.4.0傳遞依賴問題

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>spring-boot-test</groupId> 
    <artifactId>spring-boot-test</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.4.0.RELEASE</version> 
     <relativePath/> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <start-class>com.igor.Application</start-class> 
     <spring-cloud-sleuth.version>1.0.4.RELEASE</spring-cloud-sleuth.version> 
    </properties> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.springframework.cloud</groupId> 
       <artifactId>spring-cloud-sleuth</artifactId> 
       <version>${spring-cloud-sleuth.version}</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

,這裏是我的依賴關係樹:

[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building spring-boot-test 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ spring-boot-test --- 
[INFO] spring-boot-test:spring-boot-test:jar:1.0-SNAPSHOT 
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.0.RELEASE:compile 
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.4.0.RELEASE:compile 
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.4.0.RELEASE:compile 
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.0.RELEASE:compile 
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.0.RELEASE:compile 
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.7:compile 
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.1.7:compile 
[INFO] | | | +- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile 
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile 
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile 
[INFO] | | \- org.yaml:snakeyaml:jar:1.17:runtime 
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.0.RELEASE:compile 
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.4:compile 
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.4:compile 
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.4:compile 
[INFO] | +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile 
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile 
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile 
[INFO] | | \- com.fasterxml:classmate:jar:1.3.1:compile 
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.1:compile 
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.1:compile 
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.8.1:compile 
[INFO] | +- org.springframework:spring-web:jar:4.2.6.RELEASE:compile 
[INFO] | | +- org.springframework:spring-aop:jar:4.2.6.RELEASE:compile 
[INFO] | | | \- aopalliance:aopalliance:jar:1.0:compile 
[INFO] | | +- org.springframework:spring-beans:jar:4.2.6.RELEASE:compile 
[INFO] | | \- org.springframework:spring-context:jar:4.2.6.RELEASE:compile 
[INFO] | \- org.springframework:spring-webmvc:jar:4.2.6.RELEASE:compile 
[INFO] |  \- org.springframework:spring-expression:jar:4.2.6.RELEASE:compile 
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.0.RELEASE:test 
[INFO] +- org.springframework.boot:spring-boot-test:jar:1.4.0.RELEASE:test 
[INFO] +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.0.RELEASE:test 
[INFO] +- com.jayway.jsonpath:json-path:jar:2.2.0:test 
[INFO] | +- net.minidev:json-smart:jar:2.2.1:test 
[INFO] | | \- net.minidev:accessors-smart:jar:1.1:test 
[INFO] | |  \- org.ow2.asm:asm:jar:5.0.3:test 
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.21:compile 
[INFO] +- junit:junit:jar:4.12:test 
[INFO] +- org.assertj:assertj-core:jar:2.5.0:test 
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test 
[INFO] | \- org.objenesis:objenesis:jar:2.1:test 
[INFO] +- org.hamcrest:hamcrest-core:jar:1.3:test 
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test 
[INFO] +- org.skyscreamer:jsonassert:jar:1.3.0:test 
[INFO] | \- org.json:json:jar:20140107:test 
[INFO] +- org.springframework:spring-core:jar:4.3.2.RELEASE:compile 
[INFO] \- org.springframework:spring-test:jar:4.2.6.RELEASE:test 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.126 s 
[INFO] Finished at: 2017-07-07T20:25:23+03:00 
[INFO] Final Memory: 21M/437M 
[INFO] ------------------------------------------------------------------------ 

它看起來像spring-boot-sleuth重寫了依賴關係,導致Spring Boot 1.4使用spring 4.3.2.RELEASE。 我不需要它,如何避免這種行爲?

+0

https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html –

+0

ok ,但這真的很容易出錯,我花了整整一天的時間來弄清楚爲什麼我的spring-core 4.2.6而不是4.3.2 – idmitriev

+0

「這真是容易出錯」 - 這是什麼? Maven依賴管理,還是你的代碼? –

回答

2

您可以排除Maven中的依賴關係。但是,您應該考慮使用發行版BOM,以便爲您選擇最佳匹配依賴關係

+0

我使用春季啓動作爲BOM已經,但通過母pom – idmitriev

+1

是的,但你應該使用雲物料清單 - http://projects.spring.io/spring-cloud/ –

+0

真棒,它的工作原理,謝謝 – idmitriev