我知道有很多关于SLF4J问题的帖子,但没有一个能帮助我解决我的问题。
我创建了一个带有Spring Initializer的新项目,其中依赖项web
,rest
和mvn clean install
以及导入的文件作为模块下载到新的IntelliJ项目中。
我可以做SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/IntelliJ%20IDEA.app/Contents/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/matteweon/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.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]
并且它有效。但这是我在运行主类时得到的错误消息:
<?xml version="1.0" encoding="UTF-8"?>
<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>poc.local</groupId>
<artifactId>robot-shop-store</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>robot-shop-store</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<!--exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<!--exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>
</plugin>
</plugins>
</build>
</project>
这是我的pom.xml:
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/Applications/IntelliJ%20IDEA.app/Contents/lib/slf4j-log4j12-1.7.10.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory
我尝试在mongodb和data-rest依赖项下向slf4j添加一些排除项(您可以在此文件中看到注释),并为另一个添加了错误:
$.each( this.data, function(key,value){
$.each( value.tags, function(i, j){
console.log("TAGS", j);
var array = [];
var items = array.push(j);
console.log("ITEMS ARRAY", array);
$("ul.tag-list").append("<li><span class='tag is-link'>" + j + "</span></li>");
});
});
有什么想法吗?
答案 0 :(得分:0)
当我尝试运行另一个项目时,我已经完成了相同的依赖项,它运行得很好,所以我知道不是导致问题的项目,而是IntelliJ本身。所以我在IntelliJ和IntelliJ的配置文件(.iml文件和.idea文件夹)上删除了我的模块,我重新导入了项目,现在它正在工作
答案 1 :(得分:0)
我对pom.xml文件做了很多更改,例如对slf4j的专有权,但无济于事。最后通过删除slf4j-log4j12-1.7.10.jar解决了该问题。这应该可以解决您的问题。
Jar路径: 文件:/Applications/IntelliJ%20IDEA.app/Contents/lib/slf4j-log4j12-1.7.10.jar