在Spring-boot/Security中偏爱LogBack优于Log4j [英] Favoring LogBack over Log4j in spring-boot/ security

查看:127
本文介绍了在Spring-boot/Security中偏爱LogBack优于Log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该版本的spring-boot <version>1.3.3.RELEASE</version>出现了问题,以前的版本中我从未使用过. 一切都在intelij中运行良好.但是,当我想使用mvn spring-boot:run运行打包版本时,出现类路径地狱错误:

Im having a problem with this version of spring-boot <version>1.3.3.RELEASE</version> Which I did not use to have in prior versions. Everything runs fine in intelij. however when i want to run the packaged version with mvn spring-boot:run I get a classpath hell error :

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/Users/jstuartmilne/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.4.1/log4j-slf4j-impl-2.4.1.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.apache.logging.slf4j.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext

之所以选择Logback,是因为在以前的spring-boot版本中,Logback是我实现较少问题的日志记录实现.但是,此版本的spring-boot并非如此. 现在我已完成所有设置,因此我想继续使用Logback.

I chose Logback because in prior spring-boot versions Logback was the logging implementation I would have less problems with. However this is not the case for this version of spring-boot. I Would like to stay with Logback now that I have everything setup with it.

这是我的pom.xml的样子:

This is how my pom.xml look like :

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

        <version>1.3.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <google-api.version>1.20.0</google-api.version>
        <postgresql.version>9.3-1103-jdbc41</postgresql.version>
        <scala.version>2.10.4</scala.version>
        <activiti.version>5.17.0</activiti.version>
        <spring-security-test.version>4.0.1.RELEASE</spring-security-test.version>

    </properties>

    <dependencies>

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

        <!-- Google Api Client -->
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>${google-api.version}</version>
        </dependency>

        <dependency>
            <groupId>com.google.http-client</groupId>
            <artifactId>google-http-client-jackson</artifactId>
            <version>${google-api.version}</version>
        </dependency>


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


        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgresql.version}</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>2.13.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
            <version>8.0.15</version>
        </dependency>

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

        <!--Used to manage workflows-->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>spring-boot-starter-jpa</artifactId>
            <version>${activiti.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.6.4</version>
        </dependency>

        <!--Functional enhancements-->
        <dependency>
            <groupId>com.javaslang</groupId>
            <artifactId>javaslang</artifactId>
            <version>2.0.0-RC2</version>
        </dependency>

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

        <!--Used to manage authentication tokens-->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.6.9</version>
        </dependency>

        <!--Used to manage excel export-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.8</version>
        </dependency>

        <!--Used to manage the sending of emails-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <!--PayPal Sdk-->
        <dependency>
            <groupId>com.paypal.sdk</groupId>
            <artifactId>rest-api-sdk</artifactId>
            <version>LATEST</version>
        </dependency>

        <!--Mandrill SDK-->
        <dependency>
            <groupId>com.mandrillapp.wrapper.lutung</groupId>
            <artifactId>lutung</artifactId>
            <version>0.0.5</version>
        </dependency>

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


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

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </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>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>

            </plugin>
        </plugins>
    </build>

</project>

现在运行mvn dependency:tree会返回以下内容:

Now running a mvn dependency:tree returns this :

[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ timeoff ---
[INFO] com.asimplemodule:timeoff:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.3.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.5:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.5:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.16:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.16:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.16:runtime
[INFO] |  +- org.springframework:spring-aop:jar:4.2.5.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.0.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.0.3.RELEASE:compile
[INFO] |     \- org.springframework:spring-web:jar:4.2.5.RELEASE:compile
[INFO] +- com.google.api-client:google-api-client:jar:1.20.0:compile
[INFO] |  +- com.google.oauth-client:google-oauth-client:jar:1.20.0:compile
[INFO] |  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.http-client:google-http-client-jackson2:jar:1.20.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.6.5:compile
[INFO] |  \- com.google.guava:guava-jdk5:jar:13.0:compile
[INFO] +- com.google.http-client:google-http-client-jackson:jar:1.20.0:compile
[INFO] |  +- com.google.http-client:google-http-client:jar:1.20.0:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.11:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.3.3.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.8:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.3.3.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.2.5.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.9.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-orm:jar:4.2.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.2.5.RELEASE:compile
[INFO] +- org.postgresql:postgresql:jar:9.3-1103-jdbc41:compile
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.8.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:4.2.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.2.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.2.5.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.11.4.RELEASE:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.16:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.16:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.13.0:compile
[INFO] +- org.apache.tomcat:tomcat-jdbc:jar:8.0.15:compile
[INFO] |  \- org.apache.tomcat:tomcat-juli:jar:8.0.15:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.32:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.32:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.32:compile
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.32:compile
[INFO] +- org.activiti:spring-boot-starter-jpa:jar:5.17.0:compile
[INFO] |  \- org.activiti:spring-boot-starter-basic:jar:5.17.0:compile
[INFO] |     +- org.activiti:activiti-engine:jar:5.17.0:compile
[INFO] |     |  +- org.activiti:activiti-bpmn-converter:jar:5.17.0:compile
[INFO] |     |  |  \- org.activiti:activiti-bpmn-model:jar:5.17.0:compile
[INFO] |     |  |     \- com.fasterxml.jackson.core:jackson-databind:jar:2.6.5:compile
[INFO] |     |  |        \- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.5:compile
[INFO] |     |  +- org.activiti:activiti-process-validation:jar:5.17.0:compile
[INFO] |     |  +- org.activiti:activiti-image-generator:jar:5.17.0:compile
[INFO] |     |  +- org.apache.commons:commons-email:jar:1.2:compile
[INFO] |     |  |  \- javax.mail:mail:jar:1.4.1:compile
[INFO] |     |  +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO] |     |  +- org.mybatis:mybatis:jar:3.2.5:compile
[INFO] |     |  \- joda-time:joda-time:jar:2.8.2:compile
[INFO] |     \- org.activiti:activiti-spring:jar:5.17.0:compile
[INFO] |        \- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] |           \- commons-pool:commons-pool:jar:1.6:compile
[INFO] +- org.apache.velocity:velocity:jar:1.6.4:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.4:compile
[INFO] |  \- oro:oro:jar:2.0.8:compile
[INFO] +- com.javaslang:javaslang:jar:2.0.0-RC2:compile
[INFO] +- net.sf.ehcache:ehcache-core:jar:2.6.9:compile
[INFO] +- org.apache.poi:poi:jar:3.8:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.5:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.2.5.RELEASE:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.5.5:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- com.paypal.sdk:rest-api-sdk:jar:1.7.0:compile
[INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.4.1:compile
[INFO] |  +- com.google.code.gson:gson:jar:2.3.1:compile
[INFO] |  +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.4.1:compile
[INFO] |  \- org.apache.logging.log4j:log4j-api:jar:2.4.1:compile
[INFO] +- com.mandrillapp.wrapper.lutung:lutung:jar:0.0.5:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.1:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.4.4:compile
[INFO] |  \- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.3.3.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.3.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-test:jar:4.0.3.RELEASE:test
[INFO] |  +- org.springframework.security:spring-security-core:jar:4.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.2.5.RELEASE:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.0.0:test
[INFO] |  \- net.minidev:json-smart:jar:2.1.1:test
[INFO] |     \- net.minidev:asm:jar:1.0.2:test
[INFO] |        \- asm:asm:jar:3.3.1:test
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.3.3.RELEASE:test
[INFO]    +- junit:junit:jar:4.12: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] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.708 s
[INFO] Finished at: 2016-06-28T09:13:33-03:00
[INFO] Final Memory: 25M/437M
[INFO] ------------------------------------------------------------------------

我可以从依赖关系树中看到导致问题的软件包是paypals和spring-security.

I can see by the dependency tree that the packages that cause the problem are paypals AND spring-security.

当我尝试排除log4j时.弹簧安全停止工作.它只是找不到课程 : class path resource [org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.class] cannot be opened because it does not exist

When i try to exclude log4j. spring-security stops working. it just cant find classes : class path resource [org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.class] cannot be opened because it does not exist

有没有一种方法可以解决此问题而不必迁移到log4j? 预先感谢

Is there a way o can solve this without having to migrate to log4j ? Thanks in advance

推荐答案

org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.class

这与排除log4j无关吗? 您是如何排除它的?

This as nothing to do with excluding log4j ? How did you excluded it ?

应类似于:

 <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope> 
        <exclusions>
          <exclusion>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
          </exclusion>
        </exclusions>
 </dependency>

这篇关于在Spring-boot/Security中偏爱LogBack优于Log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆