Java Eclipse + Spring Boot 中“throw new SilentExitException()”处的断点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32770884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Breakpoint at "throw new SilentExitException()" in Eclipse + Spring Boot
提问by Bruno De Freitas Barros
Everytime I run my Spring Boot project on debug mode in Eclipse IDE (Spring Tool Suite), the thread stops at "throw new SilentExitException();" line even without a breakpoint.
每次我在 Eclipse IDE(Spring 工具套件)中以调试模式运行 Spring Boot 项目时,线程都会在“throw new SilentExitException();”处停止。即使没有断点也行。
Some solution to avoid this behavior?
避免这种行为的一些解决方案?
org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread() (line 53):
org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread()(第 53 行):
public static void exitCurrentThread() {
throw new SilentExitException();
}
This starts happening after upgrade to 1.3.0 Milestones.
这在升级到 1.3.0 里程碑后开始发生。
Spring Tool Suite Version: 3.7.0.RELEASE Build Id: 201506290649 Platform: Eclipse Luna SR2 (4.4.2)
Spring Tool Suite 版本:3.7.0.RELEASE Build Id:201506290649 平台:Eclipse Luna SR2 (4.4.2)
采纳答案by Phil Webb
This is unfortunately a know issue with the new spring-boot-devtools
module (see https://github.com/spring-projects/spring-boot/issues/3100). We use this trick to kill the main thread so that we can replace it with a re-loadable version. So far I've not found a way to prevent the debug breakpoint from triggering.
不幸的是,这是新spring-boot-devtools
模块的一个已知问题(请参阅https://github.com/spring-projects/spring-boot/issues/3100)。我们使用这个技巧杀死主线程,以便我们可以用可重新加载的版本替换它。到目前为止,我还没有找到防止触发调试断点的方法。
For now, you can toggle the "suspend execution on uncaught exceptions" checkbox in Java -> Debug preferences to prevent it from happening.
现在,您可以在 Java -> Debug 首选项中切换“在未捕获的异常上暂停执行”复选框以防止它发生。
回答by RichN
As Eclipse on Debug mode already allows limited hotpatching, I find the reloader to be counterproductive most of the time and so I decided to disable it by:
由于调试模式下的 Eclipse 已经允许有限的热修补,我发现重新加载器在大多数情况下会适得其反,因此我决定通过以下方式禁用它:
System.setProperty("spring.devtools.restart.enabled", "false");
参考:https: //docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable
Since that exception is thrown by the reloader, this also solves this issue. Note that you'll have to use the System.setProperty
method instead of setting it in application.properties
.
由于该异常是由重新加载器抛出的,因此这也解决了这个问题。请注意,您必须使用该System.setProperty
方法而不是将其设置在application.properties
.
回答by ra1729
Try to run devtools at scope runtime:
尝试在范围运行时运行 devtools:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
回答by xbranko
回答by Dan Thomas
My workaround:
我的解决方法:
public static void main(String[] args) {
try {
SpringApplication.run(App.class, args);
} catch (Throwable e) {
if(e.getClass().getName().contains("SilentExitException")) {
LOGGER.debug("Spring is restarting the main thread - See spring-boot-devtools");
} else {
LOGGER.error("Application crashed!", e);
}
}
}
It doesn't matter that we ignore the SilentExitException
because the devtools are just restarting the instance with a SilentExitException
which isn't very silent. This try block will silence it...
我们忽略 并不重要,SilentExitException
因为 devtools 只是用一个SilentExitException
不是很安静的a 重新启动实例。这个 try 块将使其静音...
I had to use text matching on the class as the SilentExitException
is private in SilentExitExceptionHandler
.
我不得不使用文本匹配的类作为SilentExitException
在私人SilentExitExceptionHandler
。
It doesn't solve your problem with the breakpoint...
它不能解决您的断点问题...