mattshma/bigdata

Class path contains multiple SLF4J bindings

mattshma opened this issue · 1 comments

启动 Tomcat 后,报错如下:

26-Jul-2018 13:55:17.539 信息 [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/java/target/web/WEB-INF/lib/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:java/target/web/WEB-INF/lib/slf4j-log4j12-1.7.10.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
13:55:17.685 [RMI TCP Connection(2)-127.0.0.1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
13:55:17.846 [RMI TCP Connection(2)-127.0.0.1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
13:55:17.846 [RMI TCP Connection(2)-127.0.0.1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
13:55:17.851 [RMI TCP Connection(2)-127.0.0.1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [jndiProperties] PropertySource with lowest search precedence
13:55:17.851 [RMI TCP Connection(2)-127.0.0.1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
13:55:17.853 [RMI TCP Connection(2)-127.0.0.1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence

奇怪的是之前启动是没有这些信息,看上述输出应该是多个 slf4j 绑定导致的。

由于基本代码和配置基本没作修改,只是额外导入了一个包,基本可以断定是和该包有关,查看项目依赖的包,确实有 logback-classicslf4j-log4j,由于 slf4j-log4j 是在项目中用到的,因此在新引入的项目中,将 logback-classic 排除即可。

<dependency>
	<groupId>xxx.xxxx.xxx</groupId>
	<artifactId>xxxxxxxxx</artifactId>
	<version>xx-SNAPSHOT</version>
	<exclusions>
		<exclusion>
			<artifactId>logback-classic</artifactId>
			<groupId>ch.qos.logback</groupId>
		</exclusion>
	</exclusions>
</dependency>

重新打包即可。