Jus*_*ice 4 java spring spring-boot
我有一个 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)
Run Code Online (Sandbox Code Playgroud)
主要类如下
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
发现问题了。这是由于spring-boot-maven-plugin版本 1.5.7 和 2.1.6 之间重新打包分类器发生变化(请参阅此处)
我的 1.5.7 pomspring-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>
Run Code Online (Sandbox Code Playgroud)
升级到发行版后,构建生成的清单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
Run Code Online (Sandbox Code Playgroud)
将 更改spring-boot-maven-plugin:2.2.16为以下内容修复了问题 - jarMANIFEST现在包含正确的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>
Run Code Online (Sandbox Code Playgroud)
正确的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
Run Code Online (Sandbox Code Playgroud)
该应用程序现在可以正常启动。
| 归档时间: |
|
| 查看次数: |
3561 次 |
| 最近记录: |