我有一个spring boot 2应用程序,当在IDE(IntelliJ)中运行时,该应用程序会启动并按预期运行。 但是,当我通过命令行(java -jar app.jar)运行应用程序时,出现了StackOverFlowError异常。
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);
}
}
答案 0 :(得分:0)
发现了问题。这是由于spring-boot-maven-plugin
重新打包分类器在1.5.7版和2.1.6版(see here)之间发生了更改
我的1.5.7 pom的spring-boot-maven-plugin
的配置如下:
<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
。
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
。
<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
应用现在可以正常运行了。
答案 1 :(得分:0)
对我来说,我将mainClass添加到spring boot maven插件中,并且正确生成了MANIFEST文件。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.test.App</mainClass>
<finalName>JarName</finalName>
</configuration>
</execution>
</executions>