slf4j 无法绑定记录器,尽管 logback 存在于类路径中
slf4j fails to bind logger, despite logback existing on classpath
当 运行 对项目进行集成测试时,会记录以下错误:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
根据文档,只有当记录器实现不在类路径中时才会发生此错误,但是,存在以下 Maven 依赖项:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback}</version>
<scope>compile</scope>
</dependency>
此外,当 Neo4j 2.x 在类路径中时,问题 不会发生 ,但是对于 Neo4j 3.x 它会发生。
我该如何解决这个问题?
我遇到了同样的问题。您可以尝试在您的类路径上找到所有 Logback 依赖项,并且 remove/shade 所有这些都是重复的。
看看这个 link,也许会有帮助:http://www.slf4j.org/codes.html#StaticLoggerBinder
这里也一样。试试这个:
mvn dependency:tree -Dincludes=org.slf4j:slf4j-api
# you can add "-DoutputType=dot | grep -E "log|slf4j" to get a better idea
在所有传递依赖项(dep of deps)中进行深度搜索。您可能会发现您的一些依赖项正在使用 slf4j。
如果是这种情况,请将 slf4j 添加到您的项目 pom 中作为直接 dep,这样您就可以隐藏 dep 中使用的那个。并在您的项目中也添加 logback/log4j dep。
我用这个:
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
其中 ${slf4j.version}
是 1.7.9
,当前稳定的(没有 alpha/beta 后缀)。
当 运行 对项目进行集成测试时,会记录以下错误:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
根据文档,只有当记录器实现不在类路径中时才会发生此错误,但是,存在以下 Maven 依赖项:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback}</version>
<scope>compile</scope>
</dependency>
此外,当 Neo4j 2.x 在类路径中时,问题 不会发生 ,但是对于 Neo4j 3.x 它会发生。
我该如何解决这个问题?
我遇到了同样的问题。您可以尝试在您的类路径上找到所有 Logback 依赖项,并且 remove/shade 所有这些都是重复的。
看看这个 link,也许会有帮助:http://www.slf4j.org/codes.html#StaticLoggerBinder
这里也一样。试试这个:
mvn dependency:tree -Dincludes=org.slf4j:slf4j-api
# you can add "-DoutputType=dot | grep -E "log|slf4j" to get a better idea
在所有传递依赖项(dep of deps)中进行深度搜索。您可能会发现您的一些依赖项正在使用 slf4j。
如果是这种情况,请将 slf4j 添加到您的项目 pom 中作为直接 dep,这样您就可以隐藏 dep 中使用的那个。并在您的项目中也添加 logback/log4j dep。
我用这个:
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
其中 ${slf4j.version}
是 1.7.9
,当前稳定的(没有 alpha/beta 后缀)。