这两天在启动一个新项目的时候,项目一直启动不了,报StackOverFlow;html
java.util.concurrent.ExecutionException: java.lang.StackOverflowError
这个问题第一反应就是启动参数里面JVM永久区配置的小了或者没有配置,好的,直接加上配置前端
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <path>app</path> <port>8080</port> <uriEncoding>UTF-8</uriEncoding> <systemProperties> <JAVA_OPTS>-Xms256m -Xmx2048m -XX:MaxPermSize=1024m</JAVA_OPTS> </systemProperties> </configuration> <version>2.2</version> </plugin>
再启动试试:java
仍是报错,难道咱们的配置没有生效,或者缓存没有从新BUILD,各类骚操做以后仍是不行,web
由于这个项目生产上是已经部署的,因此代码应该没有问题,仍是好好看日志吧,spring
无心中发现一个警告信息:apache
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/XX/.m2/repository/org/slf4j/slf4j-log4j12/1.7.6/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/XX/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
是否是Jar冲突了?带着这种想法去查项目,而后各类缓存
<exclusion></exclusion>
在网上看到一个很好的帖子,说的很详细,这里直接贴下原文
Class path contains multiple SLF4J bindings.
警告的解决有一次配置好springboot项目启动后,突然发现有下边的警告:tomcat
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/E:/mavenJarOnline/ch/qos/logback/logback-classic/1.1.9/logback-classic-1.1.9.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/E:/mavenJarOnline/org/slf4j/slf4j-log4j12/1.7.22/slf4j-log4j12-1.7.22.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]
上边的大概意思是说logback-classic
包和slf4j-log4j12
包,关于org/slf4j/impl/StaticLoggerBinder.class
这个类发生了冲突。
发生这个错误的缘由,首先logback
日志的开发者和log4j
的开发者听说是一波人,而springboot
默认日志是,较新的logback
日志。可是在之前流行的日志倒是log4j
,并且不少的第三方工具都含有log4j
得引入。
而咱们在项目开发中,不免会引入各类各样的工具包,因此,基本上springboot
项目,若是不注意,确定会出现这种冲突的。springboot
固然最关心的是它是否有隐患,若是你在开发工具中运行,对,没毛病,通常
会正常启动。
通过我使用状况中的观察,貌似springboot
配置成tomcat运行
,即修改为war
包以后,通常这个警告没有什么影响;可是若是是传统的jar
包,尽管你在开发工具中能正常运行,也可能在打完包以后不能运行。ruby
由于咱们是分布式项目开发,服务层做为一个jar
运行,而接口调用和前端页面,做为一个war
一块儿运行,也就是说咱们即有war
,又有jar
,项目部署的时候,须要打完包以后运行才能够。
在打完包以后,war
包能正常运行,jar
包不能正常运行,报了以下错误:
Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner .java:48) at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: java.lang.ExceptionInInitializerError at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72) at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45 ) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogF actory.java:155) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogF actory.java:132) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) at org.springframework.boot.SpringApplication.<clinit>(SpringApplication .java:190) at spingboot.study.SpringbootStudyApplication.main(SpringbootStudyApplic ation.java:14) ... 8 more Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar A ND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details. at org.slf4j.impl.Log4jLoggerFactory.<clinit>(Log4jLoggerFactory.java:54 ) ... 19 more
固然问题我不敢肯定必定是由于war
和jar
的缘由,大家也可能不关心这个,咱们只想知道如何解决这种问题而已。
问题解决办法很简单,就是既然抛了jar包冲突
,那咱们就排除一个jar
包便可。关键是排除哪个jar包
,这里注意下了,若是你用的是logback
日志,必定要排除slf4j-log4j12
包,不要排除logback-classic
包。
即找到pom.xml
文件,若是大家的开发工具,好比eclipse
和idea
均可以看引入jar
包的联系,好比idea能够这样看到你的依赖结构:
点击后,弹出下边的这样的结构:
经过上图中,你能够看到zookeeper
包中默认引入了slf4j-log4j12
包,除此以外,还有咱们springboot
必定引入的spring-boot-starter-web
包,它里边也有这个slf4j-log4j12
引入。
咱们只要在pom.xml
里排除这个便可。
以下:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--排除这个slf4j-log4j12--> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency>
下边是咱们项目引入的第三方的工具包中:
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.8</version>
<!--排除这个slf4j-log4j12-->
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
基本上按照这个思路就能解决问题,我这边实际中遇到的就是一个引人的jar中引人了这个jar而致使的!