SpringBoot 2 (2.1.6.RELEASE) StackOverFlowError [英] SpringBoot 2 (2.1.6.RELEASE) StackOverFlowError
问题描述
我有一个 spring boot 2 应用程序,它在 IDE (IntelliJ) 中运行时按预期启动和运行.但是,当我通过命令行 (java -jar app.jar) 运行应用程序时,出现 StackOverFlowError 异常.
I have a spring boot 2 application which starts and runs as expected when run in the IDE (IntelliJ). However, when I run the app via the commandline (java -jar app.jar), I get a StackOverFlowError exception.
Caused by: java.lang.reflect.InvocationTargetException
... 1024 more
Caused by: java.lang.reflect.InvocationTargetException
... 1024 more
Caused by: java.lang.reflect.InvocationTargetException
... 1024 more
Caused by: java.lang.StackOverflowError
at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1012)
at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1535)
at java.lang.ClassLoader.getClassLoadingLock(ClassLoader.java:463)
at java.lang.ClassLoader.loadClass(ClassLoader.java:404)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
主要类如下
@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@EntityScan(basePackages="x.y.z")
@EnableJpaRepositories
@EnableTransactionManagement
@EnableAspectJAutoProxy
@EnableScheduling
@EnableAsync
@EnableRetry
@Slf4j
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
推荐答案
发现问题.这是由于 spring-boot-maven-plugin
重新打包分类器在 1.5.7 和 2.1.6 版之间发生了变化(见这里)
Found the problem. This was due to the spring-boot-maven-plugin
repackage classifier changes between version 1.5.7 and 2.1.6 (see here)
我的1.5.7 pom的spring-boot-maven-plugin
配置如下:
My 1.5.7 pom's spring-boot-maven-plugin
was configured as follows:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
<additionalProperties>
<build.number>${buildNumber}</build.number>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
在升级到 spring-boot-maven-plugin:2.2.16
版本后,生成的清单没有正确的 Start-Class
.>
The resulting manifest from the build, after upgrading to spring-boot-maven-plugin:2.2.16
release does not have the correct Start-Class
.
Manifest-Version: 1.0
Implementation-Title: my-app
Implementation-Version: 2.1.0-SNAPSHOT
Start-Class: org.springframework.boot.loader.JarLauncher
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Build-Jdk-Spec: 1.8
Spring-Boot-Version: 2.1.6.RELEASE
Created-By: Maven Archiver 3.4.0
Main-Class: org.springframework.boot.loader.JarLauncher
将 spring-boot-maven-plugin:2.2.16
更改为以下解决了该问题 - jar MANIFEST
现在包含正确的 Start-Class代码>.
Changing the spring-boot-maven-plugin:2.2.16
to the following fixed the issue - the jar MANIFEST
now contains the correct Start-Class
.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
<additionalProperties>
<build.number>${buildNumber}</build.number>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
正确的MANIFEST
:
Manifest-Version: 1.0
Implementation-Title: my-app
Implementation-Version: 2.1.0-SNAPSHOT
Start-Class: my.app.MainClass
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Build-Jdk-Spec: 1.8
Spring-Boot-Version: 2.1.6.RELEASE
Created-By: Maven Archiver 3.4.0
Main-Class: org.springframework.boot.loader.JarLauncher
应用现在可以正常启动.
The app now starts fine.
这篇关于SpringBoot 2 (2.1.6.RELEASE) StackOverFlowError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!