【问题标题】:commons-logging lost in spring-core in maven?commons-logging在maven的spring-core中丢失了?
【发布时间】:2019-03-08 08:49:40
【问题描述】:

下面是我的 pom.xml

<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/maven-v4_0_0.xsd">

    <properties>
        <jdk.version>1.8</jdk.version>
        <spring.version>4.1.6.RELEASE</spring.version>

    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

    </dependencies>

</project>

我可以通过'mvn dependency:tree'打印依赖树

\- org.springframework:spring-webmvc:jar:4.1.6.RELEASE:compile
[INFO]    +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
[INFO]    +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
[INFO]    |  \- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
[INFO]    |     \- aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
[INFO]    |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO]    +- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO]    \- org.springframework:spring-web:jar:4.1.6.RELEASE:compile

您可以看到 commons-loggingspring-core 下。

但是当我改到下面的时候。

<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/maven-v4_0_0.xsd">

    <properties>
        <jdk.version>1.8</jdk.version>
        <spring.version>4.1.6.RELEASE</spring.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>1.1.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

并打印以下树。

INFO] \- org.springframework:spring-webmvc:jar:4.1.6.RELEASE:compile
[INFO]    +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
[INFO]    +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
[INFO]    |  \- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
[INFO]    |     \- aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
[INFO]    +- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO]    \- org.springframework:spring-web:jar:4.1.6.RELEASE:compile

可以发现commons-logging丢失了。

我可以在 IDE 中点击进入 spring-webmvc 的子节点,并确认 commons-logging 存在于 spring-core-4.1.6 中。 RELEASE.pom

我遇到了这个问题,因为我想从 spring 中排除 commons-logging 并计划使用 jcl-over-slf4j。那么为什么我使用 io.spring.platform 时会丢失 commons-logging jar 文件。谢谢。

【问题讨论】:

  • 根据doc不推荐使用commons-logging

标签: java spring maven


【解决方案1】:

通过导入一个 pom,您可以在该 pom 中应用dependencyManagement,还应用来自它的父级和它的父级的父级的dependencyManagement 等等。

spring platform-b​​om:1.1.2.RELEASE 扩展自spring-boot-starter-parent:1.2.3.RELEASE。在那个父 pom 中有一个 dependencyManagement 部分已经排除了 commons-logging:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</dependencyManagement>

【讨论】:

    猜你喜欢
    • 2014-05-04
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 2019-01-23
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多