简体   繁体   English

为什么我不能在spring-boot中使用apache httpcomponents对象,即使它列在MVN依赖项中?

[英]Why can't I use an apache httpcomponents object in spring-boot, even though it is listed in the MVN dependancies?

Spring-boot has the following maven dependencies around org.apache.httpcomponents Spring-boot在org.apache.httpcomponents周围有以下maven依赖项

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpasyncclient</artifactId>
    <version>${httpasyncclient.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>${httpclient.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>${httpclient.version}</version>
</dependency>

However I don't have access to anything org.apache.http related in my codebase unless I add the extra dependency myself. 但是,除非我自己添加额外的依赖,否则我无法访问代码库中相关的任何org.apache.http。

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
</dependency>

Why is this? 为什么是这样? Isn't this the same as adding a dependency twice? 这与两次添加依赖项不一样吗?

The artifacts are declared in the dependencyManagement section of the spring-boot-dependencies pom. 工件在spring-boot-dependencies pom的dependencyManagement部分中声明。

Meaning when you inherit from the spring boot starter, you can declare you want to use any of the dependencies managed by it. 从spring boot starter继承时的含义,您可以声明要使用由它管理的任何依赖项。 Notice you don't need to provide a version of the httpclient. 请注意,您不需要提供httpclient的版本。 This is because Spring has so nicely managed it for you, hence dependencyManagement. 这是因为Spring已经很好地管理了它,因此依赖管理。 So it is not the same thing as declaring it twice. 因此,将它声明两次并不是一回事。

More info here http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-parent-pom 更多信息,请访问http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-parent-pom

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM