使用spring-jcl的标准Commons Logging发现功能示例。

huangapple go评论53阅读模式
英文:

Standard Commons Logging discovery in action with spring-jcl

问题

这是您的Spring Boot项目的依赖关系清单,不过它包含了一条控制台消息,建议从类路径中移除commons-logging.jar以避免潜在冲突。

以下是依赖关系清单的一部分:

  • org.springframework.boot:spring-boot-starter-data-jpa:jar:3.1.1 - Spring Boot的数据JPA支持
  • org.springframework.boot:spring-boot-starter-security:jar:3.1.1 - Spring Boot的安全性支持
  • org.springframework.boot:spring-boot-starter-validation:jar:3.1.1 - Spring Boot的验证支持
  • org.springframework.boot:spring-boot-starter-web:jar:3.1.1 - Spring Boot的Web支持
  • org.projectlombok:lombok:jar:1.18.28 - Lombok库,用于简化Java代码
  • com.mashape.unirest:unirest-java:jar:1.4.9 - Unirest库,用于处理HTTP请求
  • com.mysql:mysql-connector-j:jar:8.0.33 - MySQL数据库连接驱动
  • io.jsonwebtoken:jjwt-api:jar:0.11.5 - JSON Web Token (JWT) 的API
  • io.jsonwebtoken:jjwt-impl:jar:0.11.5 - JSON Web Token (JWT) 的实现
  • io.jsonwebtoken:jjwt-jackson:jar:0.11.5 - JSON Web Token (JWT) 的Jackson集成
  • org.springframework.boot:spring-boot-starter-test:jar:3.1.1 - Spring Boot的测试支持
  • org.springframework.security:spring-security-test:jar:6.1.1 - Spring Security的测试支持

请注意,这只是依赖关系的一部分,还有其他依赖项。如果您需要更多具体信息或有其他问题,请随时提出。

英文:

I have a springBoot all with these dependencies:

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

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

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

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

		<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.18.28</version>
			<scope>provided</scope>
		</dependency>

		<!-- https://mvnrepository.com/artifact/com.mashape.unirest/unirest-java -->
		<dependency>
			<groupId>com.mashape.unirest</groupId>
			<artifactId>unirest-java</artifactId>
			<version>1.4.9</version>
		</dependency>

		<dependency>
			<groupId>com.mysql</groupId>
			<artifactId>mysql-connector-j</artifactId>
			<scope>runtime</scope>
		</dependency>

		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt-api</artifactId>
			<version>0.11.5</version>
		</dependency>

		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt-impl</artifactId>
			<version>0.11.5</version>
			<scope>runtime</scope>
		</dependency>

		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt-jackson</artifactId>
			<version>0.11.5</version>
			<scope>runtime</scope>
		</dependency>


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

		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-test</artifactId>
			<scope>test</scope>
		</dependency>
    </dependencies>

but I have this message on the console:

Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts

Here the mvn dependency:tree :

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< com.planets:com.planets >-----------------
[INFO] Building planets 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- dependency:3.5.0:tree (default-cli) @ com.planets ---
[INFO] com.planets:com.planets:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:3.1.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:3.1.1:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.9.19:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:3.1.1:compile
[INFO] |  |  +- com.zaxxer:HikariCP:jar:5.0.1:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:6.0.10:compile
[INFO] |  +- org.hibernate.orm:hibernate-core:jar:6.2.5.Final:compile
[INFO] |  |  +- jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
[INFO] |  |  +- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.5.1.Final:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:6.0.6.Final:runtime
[INFO] |  |  +- io.smallrye:jandex:jar:3.0.5:runtime
[INFO] |  |  +- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.14.5:runtime
[INFO] |  |  +- org.glassfish.jaxb:jaxb-runtime:jar:4.0.3:runtime
[INFO] |  |  |  \- org.glassfish.jaxb:jaxb-core:jar:4.0.3:runtime
[INFO] |  |  |     +- org.eclipse.angus:angus-activation:jar:2.0.1:runtime
[INFO] |  |  |     +- org.glassfish.jaxb:txw2:jar:4.0.3:runtime
[INFO] |  |  |     \- com.sun.istack:istack-commons-runtime:jar:4.1.2:runtime
[INFO] |  |  +- jakarta.inject:jakarta.inject-api:jar:2.0.1:runtime
[INFO] |  |  \- org.antlr:antlr4-runtime:jar:4.10.1:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:3.1.1:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:3.1.1:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:6.0.10:compile
[INFO] |  |  +- org.springframework:spring-context:jar:6.0.10:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:6.0.10:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:6.0.10:compile
[INFO] |  |  +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:2.0.7:compile
[INFO] |  \- org.springframework:spring-aspects:jar:6.0.10:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:3.1.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:3.1.1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:3.1.1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:3.1.1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:3.1.1:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.4.8:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.4.8:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.20.0:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.20.0:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:2.0.7:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.33:compile
[INFO] |  +- org.springframework:spring-aop:jar:6.0.10:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:6.1.1:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:6.1.1:compile
[INFO] |     \- org.springframework:spring-expression:jar:6.0.10:compile
[INFO] +- org.springframework.boot:spring-boot-starter-validation:jar:3.1.1:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:10.1.10:compile
[INFO] |  \- org.hibernate.validator:hibernate-validator:jar:8.0.0.Final:compile
[INFO] |     \- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.1.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:3.1.1:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.15.2:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.15.2:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.15.2:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.1.1:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.10:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:10.1.10:compile
[INFO] |  +- org.springframework:spring-web:jar:6.0.10:compile
[INFO] |  |  \- io.micrometer:micrometer-observation:jar:1.11.1:compile
[INFO] |  |     \- io.micrometer:micrometer-commons:jar:1.11.1:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:6.0.10:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.2:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.28:provided
[INFO] +- com.mashape.unirest:unirest-java:jar:1.4.9:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.16:compile
[INFO] |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.15:compile
[INFO] |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.5:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore-nio:jar:4.4.16:compile
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.5.2:compile
[INFO] |  \- org.json:json:jar:20160212:compile
[INFO] +- com.itextpdf:itextpdf:jar:5.5.13.3:compile
[INFO] +- com.mysql:mysql-connector-j:jar:8.0.33:runtime
[INFO] +- io.jsonwebtoken:jjwt-api:jar:0.11.5:compile
[INFO] +- io.jsonwebtoken:jjwt-impl:jar:0.11.5:runtime
[INFO] +- io.jsonwebtoken:jjwt-jackson:jar:0.11.5:runtime
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.15.2:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.15.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.1.1:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:3.1.1:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.1.1:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.8.0:test
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:runtime
[INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:2.1.2:runtime
[INFO] |  +- net.minidev:json-smart:jar:2.4.11:test
[INFO] |  |  \- net.minidev:accessors-smart:jar:2.4.11:test
[INFO] |  |     \- org.ow2.asm:asm:jar:9.3:test
[INFO] |  +- org.assertj:assertj-core:jar:3.24.2:test
[INFO] |  +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] |  +- org.junit.jupiter:junit-jupiter:jar:5.9.3:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-api:jar:5.9.3:test
[INFO] |  |  |  +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |  |  |  +- org.junit.platform:junit-platform-commons:jar:1.9.3:test
[INFO] |  |  |  \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-params:jar:5.9.3:test
[INFO] |  |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.9.3:test
[INFO] |  |     \- org.junit.platform:junit-platform-engine:jar:1.9.3:test
[INFO] |  +- org.mockito:mockito-core:jar:5.3.1:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.14.5:test
[INFO] |  |  \- org.objenesis:objenesis:jar:3.3:test
[INFO] |  +- org.mockito:mockito-junit-jupiter:jar:5.3.1:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.1:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:6.0.10:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:6.0.10:compile
[INFO] |  +- org.springframework:spring-test:jar:6.0.10:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.9.1:test
[INFO] \- org.springframework.security:spring-security-test:jar:6.1.1:test
[INFO]    \- org.springframework.security:spring-security-core:jar:6.1.1:compile
[INFO]       \- org.springframework.security:spring-security-crypto:jar:6.1.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

答案1

得分: 6

如在 camunda/zeebe PR13300 中所示:

> 当使用不同版本的 commons-logging 时,Spring 会显示一个突出的警告。他们使用自己的变种 spring-jcl,导入 commons-logging 会与其冲突。

因此,我首先会尝试从项目依赖中排除 commons-logging。这将强制你的应用程序使用由Spring Boot Starter提供的日志系统。

<dependencies>
    <!-- 其他依赖项 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- 其他依赖项 -->
</dependencies>

如果其他依赖项也引入了 commons-logging,可能需要添加类似的排除项:

mvn dependency:tree | grep commons-logging
# 或者
mvn dependency:tree | findstr commons-logging

从你的Maven依赖树中:

<dependencies>
    <dependency>
        <groupId>com.mashape.unirest</groupId>
        <artifactId>unirest-java</artifactId>
        <version>1.4.9</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
英文:

As illustrated in, for instance, camunda/zeebe PR13300:

> Spring displays a prominent warning when using different versions of commons-logging. They use their own variant, spring-jcl, and importing commons-logging conflicts with this.

So I would first try and exclude commons-logging from the project dependencies. This will force your application to use the logging system provided by Spring Boot Starter.

<dependencies>
    <!-- other dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- other dependencies -->
</dependencies>

You might need to add similar exclusions to other dependencies if they also pull in commons-logging:

mvn dependency:tree | grep commons-logging
# or
mvn dependency:tree | findstr commons-logging

From your maven tree:

<dependencies>
    <dependency>
        <groupId>com.mashape.unirest</groupId>
        <artifactId>unirest-java</artifactId>
        <version>1.4.9</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

答案2

得分: 0

请尝试使用以下Maven依赖树中的排除配置:

<project>
    <!-- ... 其他项目配置 ... -->

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <!-- 在这里添加其他依赖项 -->
    </dependencies>

    <build>
        <plugins>
            <!-- 在这里添加其他构建插件 -->
            <plugin>
                <!-- 使用maven-dependency-plugin来排除commons-logging -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>exclude-commons-logging</id>
                        <goals>
                            <goal>purge-local-repository</goal>
                        </goals>
                        <configuration>
                            <groupId>commons-logging</groupId>
                            <artifactId>commons-logging</artifactId>
                            <version>1.2</version>
                            <excludes>
                                <exclude>*</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

请确保将这段配置添加到您的Maven项目的pom.xml文件中,以排除commons-logging依赖项。

英文:

can you please try the below exclusion for maven you have in dependency tree.

&lt;project&gt;
&lt;!-- ... other project configurations ... --&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- Add your other dependencies here --&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;!-- Add other build plugins here --&gt;
&lt;plugin&gt;
&lt;!-- Use maven-dependency-plugin to exclude commons-logging --&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
&lt;version&gt;3.2.0&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;exclude-commons-logging&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;purge-local-repository&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;groupId&gt;commons-logging&lt;/groupId&gt;
&lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
&lt;version&gt;1.2&lt;/version&gt;
&lt;excludes&gt;
&lt;exclude&gt;*&lt;/exclude&gt;
&lt;/excludes&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

huangapple
  • 本文由 发表于 2023年7月18日 00:55:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定