gpt4 book ai didi

java - 使用 HANA 的 Web 应用程序,获取 SLF4J : Class path contains multiple SLF4J bindings

转载 作者:太空宇宙 更新时间:2023-11-04 11:18:11 25 4
gpt4 key购买 nike

我正在构建一个 Web 应用程序,该应用程序使用 Spring 和 Hibernate 连接到 HANA 数据库,并在 SAP Cloud Platform Tomcat 8 服务器上运行。除了在服务器启动时出现错误之外,它运行没有任何问题:

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]

对于我在其他帖子中找到的内容,问题是我的 Maven 依赖项和服务器运行时之间存在冲突的 .jar 文件,但我不完全理解如何排除正确的依赖项或使用正确的库。

这是我的 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>

这是 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

知道如何解决这个问题吗?

提前致谢。

最佳答案

当部署到 Tomcat8 服务器时,我在 SAP Cloud Platform 上的 Spring Boot 应用程序上遇到了同样的问题。我通过排除 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>

希望有帮助。

关于java - 使用 HANA 的 Web 应用程序,获取 SLF4J : Class path contains multiple SLF4J bindings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45221173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com