简体   繁体   English

带有 HANA 的 Web App,获取 SLF4J:类路径包含多个 SLF4J 绑定

[英]Web App with HANA, getting SLF4J: Class path contains multiple SLF4J bindings

I'm building a web application that connects to a HANA database, using Spring and Hibernate, running on a SAP Cloud Platform Tomcat 8 server.我正在构建一个连接到 HANA 数据库的 Web 应用程序,使用 Spring 和 Hibernate,在 SAP Cloud Platform Tomcat 8 服务器上运行。 It's running with no problems except for an error I get at server startup:除了我在服务器启动时遇到的错误之外,它运行没有任何问题:

13:59:08.662 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Class path contains multiple SLF4J bindings.
13:59:08.662 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Found binding in [jar:file:/C:/neo-java-web-sdk-3.31.17.3/repository/.archive/bin/logback-classic.jar!/org/slf4j/impl/StaticLoggerBinder.class]
13:59:08.662 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Found binding in [jar:file:/C:/Eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/rbuswebapp/WEB-INF/lib/slf4j-log4j12-1.7.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
13:59:08.662 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
13:59:08.662 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

For what I managed to find on other posts, the problem is that there are conflicting .jar files between my Maven dependencies and my server runtime, but I don't fully understand how to exclude the correct dependency or use the correct library.对于我在其他帖子中找到的内容,问题是我的 Maven 依赖项和我的服务器运行时之间存在冲突的 .jar 文件,但我不完全理解如何排除正确的依赖项或使用正确的库。

This is my pom.xml file:这是我的 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.rbus.hana</groupId>
  <artifactId>rbuswebapp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

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

  <dependencies>
    <!-- Need this for json to/from object -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
  <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
        <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/java/main</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <warSourceDirectory>${basedir}/src/java/webapp</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

This is the output for mvn dependency:tree:这是 mvn dependency:tree 的输出:

mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building rbuswebapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ rbuswebapp ---
[INFO] com.rbus.hana:rbuswebapp:war:0.0.1-SNAPSHOT
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.6.4:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.4:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.4:compile
[INFO] +- org.hibernate:hibernate-core: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.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.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] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.2.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.2.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.2.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.2.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:4.2.4.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-jpa:jar:1.9.2.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.11.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-orm:jar:4.2.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.2.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.2.4.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-tx:jar:4.2.4.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjrt:jar:1.8.7:compile
[INFO] +- javax.servlet:jstl:jar:1.2:provided
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.13:runtime
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.13:runtime
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.13:runtime
[INFO] \- log4j:log4j:jar:1.2.17:runtime

Any idea on how to solve this?关于如何解决这个问题的任何想法?

Thanks in advance.提前致谢。

I had the same kind of problem on SAP Cloud Platform for a spring boot application when deploying to Tomcat8 server.部署到 Tomcat8 服务器时,我在 SAP Cloud Platform 上遇到了同样的问题,用于 Spring Boot 应用程序。 I solved it by excluding logback-classic and slf4j-api from where it came which was spring-boot-starter-data-jpa in my case.我通过排除 logback-classic 和 slf4j-api 来解决它,在我的情况下是 spring-boot-starter-data-jpa。

<dependency> 
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
    <exclusion>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </exclusion>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </exclusion>
</exclusions>

Hope it helps.希望它有帮助。

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

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