leb*_*ski 2 java spring exception exit-code spring-boot
我在 IntelliJ 中有一个 Spring Boot 应用程序,最初配置为正常启动,如下所示:
public static void main(String[] args) throws Exception {
SpringApplication.run(AccountApiApplication.class, args).close();
}
Run Code Online (Sandbox Code Playgroud)
我在方法中添加了一个 try-catch 块main来处理启动期间发生的任何错误(例如缺少配置文件等),现在看起来像:
public static void main(String[] args) throws Exception {
try {
SpringApplication.run(AccountApiApplication.class, args).close();
}
catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
Run Code Online (Sandbox Code Playgroud)
添加此后,我的应用程序总是以退出代码 1 退出。即使没有错误也是如此。我尝试打印发生的异常,它是这样的:
org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException
at org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread(SilentExitExceptionHandler.java:90)
at org.springframework.boot.devtools.restart.Restarter.immediateRestart(Restarter.java:184)
at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:163)
at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:552)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:67)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:45)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at edu.iu.es.ebs.AccountApiApplication.main(AccountApiApplication.java:90)
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
即使应用程序中没有错误,为什么我会看到此异常?当我们这样做时,是否有比在 中添加 try-catch 更好的方法来处理不可预测的启动错误main?
org.springframework.boot:spring-boot-devtools这是具有依赖项的Spring Boot 应用程序的正常工作方式。默认情况下,org.springframework.boot.devtools.restart.Restarter初始化后立即重新启动应用程序。要摆脱你应该通过将SilentExitException属性设置为摆脱重新启动程序,但我不认为这个异常是一个大问题。spring.devtools.restart.enabledfalse
| 归档时间: |
|
| 查看次数: |
3123 次 |
| 最近记录: |