类路径包含多个SLF4J绑定(无法找到它)

时间:2015-11-24 15:06:41

标签: java maven log4j slf4j logback

我知道在StackOverflow中有很多这样的问题,但无法解决如何解决我的问题:

我尝试使用logback,但是当我尝试启动我的应用时,我收到了此错误:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/slf4j-log4j12-1.7.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

请注意,实际绑定是如何替代Log4j并尝试启动log4j,但没有找到appender。

我知道我必须排除那些使用log4j的库,我无法弄清楚哪些是。

我不能使用mvn依赖:tree因为它与其他暗示的项目的依赖性而失败

8 required artifacts are missing.

来自"依赖层次结构"在日食中观察,仍然无法找到它们。

这是我的pom.xml

<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>floox</artifactId>
    <groupId>com.i3tv</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>floox-business</artifactId>
<packaging>war</packaging>
<name>Floox Business</name>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <io.spring.platform-version>1.1.1.RELEASE</io.spring.platform-version>
    <!-- AssertJ is not a part of Spring IO platform, so the version must be 
        provided explicitly -->
    <assertj-core-version>1.5.0</assertj-core-version>
    <config.root>src/main/config</config.root>
</properties>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.spring.platform</groupId>
            <artifactId>platform-bom</artifactId>
            <version>${io.spring.platform-version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
    <!-- Security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
    </dependency>
    <!-- View -->
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
        <!-- Avoid org.hibernate.jpa.boot.archive.spi.ArchiveException: Could 
            not build ClassFile in Java 8 -->
        <exclusions>
            <exclusion>
                <artifactId>javassist</artifactId>
                <groupId>org.javassist</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity3</artifactId>
    </dependency>
    <!-- Persistence -->
    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <!-- Avoid issue #72 Could not initialize class org.thymeleaf.templateresolver.ServletContextTemplateResolver 
            due to 'validation is not supported' -->
        <exclusions>
            <exclusion>
                <artifactId>pull-parser</artifactId>
                <groupId>pull-parser</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- Avoid: javax.validation.ValidationException: HV000183: Unable to load 
        'javax.el.ExpressionFactory' -->
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
    </dependency>
    <!-- Spring Data -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
    <!-- Validation -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
    <!-- Logging -->
    < <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
    </dependency>
    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- JSON -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <!-- Utilities -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>
    <!-- Test -->
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>${assertj-core-version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.objenesis</groupId>
        <artifactId>objenesis</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer</artifactId>
        <version>5.5.1</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>engine-indexer-dto</artifactId>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>temporal-hits-dto</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>floox-cloudsearch</artifactId>
        <version>${project.parent.version}</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>floox-dto</artifactId>
        <version>${project.parent.version}</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>floox-aop</artifactId>
        <version>${project.parent.version}</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>floox-memcached</artifactId>
        <version>${project.parent.version}</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>floox-utils</artifactId>
        <version>${project.parent.version}</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv</groupId>
        <artifactId>floox-token</artifactId>
        <version>${project.parent.version}</version>
    </dependency>

    <dependency>
        <groupId>com.i3tv.a3cms.social</groupId>
        <artifactId>a3cms-social-user</artifactId>
        <version>${social.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>de.javakaffee.msm</groupId>
        <artifactId>msm-kryo-serializer</artifactId>
        <version>1.9.0-RC1</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

<!-- Configuración de los perfiles -->
<profiles>
    <profile>
        <id>local</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <resources>
                <resource>
                    <directory>${config.root}/local</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </resource>
            </resources>
        </build>
        <properties>
            <profile.name>local</profile.name>
        </properties>
    </profile>
    <!-- <profile> -->
    <!-- <id>pre</id> -->
    <!-- <build> -->
    <!-- <resources> -->
    <!-- <resource> -->
    <!-- <directory>${config.root}/pre</directory> -->
    <!-- <includes> -->
    <!-- <include>**/*</include> -->
    <!-- </includes> -->
    <!-- </resource> -->
    <!-- </resources> -->
    <!-- </build> -->
    <!-- <properties> -->
    <!-- <serverId>aeb-pro</serverId> -->
    <!-- <applicationName>Flux</applicationName> -->
    <!-- <environmentName>flux-pre</environmentName> -->
    <!-- <cnamePrefix>flux-pre</cnamePrefix> -->
    <!-- <s3Bucket>flux-pre</s3Bucket> -->
    <!-- <profile.name>pre</profile.name> -->
    <!-- </properties> -->
    <!-- </profile> -->
    <profile>
        <id>pre</id>
        <build>
            <resources>
                <resource>
                    <directory>${config.root}/pre</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </resource>
            </resources>
        </build>
        <properties>
            <serverId>aeb-pre</serverId>
            <applicationName>floox-PRE</applicationName>
            <environmentName>flooxPre-env</environmentName>
            <cnamePrefix>flooxpre-env</cnamePrefix>
            <s3Bucket>fluxpre</s3Bucket>
            <profile.name>pre</profile.name>
        </properties>
    </profile>
    <profile>
        <id>pro</id>
        <build>
            <resources>
                <resource>
                    <directory>${config.root}/pro</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </resource>
            </resources>
        </build>
        <properties>
            <serverId>aeb-pro</serverId>
            <applicationName>Flux</applicationName>
            <environmentName>flux-pro</environmentName>
            <cnamePrefix>flux-pro</cnamePrefix>
            <s3Bucket>flux-pro</s3Bucket>
            <profile.name>pro</profile.name>
        </properties>
    </profile>
</profiles>
<!-- Fin de la configuración de los perfiles -->

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/</path>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>${config.root}/${profile.name}/ebextensions</directory>
                        <targetPath>.ebextensions</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>deploy</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>sources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>br.com.ingenieux</groupId>
            <artifactId>beanstalk-maven-plugin</artifactId>
            <version>1.0.1</version>
            <configuration>
                <serverId>${serverId}</serverId>
                <environmentName>${environmentName}</environmentName>
                <region>eu-west-1</region>
                <applicationName>${applicationName}</applicationName>
                <s3Bucket>${s3Bucket}</s3Bucket>
                <s3Key>${project.artifactId}/${project.build.finalName}-${maven.build.timestamp}.war</s3Key>
                <cnamePrefix>${cnamePrefix}</cnamePrefix>
                <solutionStack>64bit Amazon Linux running Tomcat 7</solutionStack>
            </configuration>
            <executions>
                <execution>
                    <phase>deploy</phase>
                    <goals>
                        <goal>upload-source-bundle</goal>
                        <goal>create-application-version</goal>
                        <goal>update-environment</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

1 个答案:

答案 0 :(得分:2)

由于dur

,我终于设法清理了我的类路径

问题是我试图从我的依赖项中排除log4j而不是slf4j jar。

因此,通过Eclipse中的依赖关系层次结构,我能够找到哪些库正在使用该依赖关系,然后通过右键单击排除Maven工件对已解决的依赖关系进行排除标签

将此代码添加到我的pom

<exclusions>
    <exclusion>
        <artifactId>slf4j-log4j12</artifactId>
        <groupId>org.slf4j</groupId>
    </exclusion>
</exclusions>

瞧,一切正常。