有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java断点位于Eclipse+Spring引导中的“抛出新的SilentExitException()”处

每次我在EclipseIDE(Spring工具套件)的调试模式下运行Spring引导项目时,即使没有断点,线程也会停在throw new SilentExitException();

有什么办法可以避免这种行为吗

org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread() (line 53):

public static void exitCurrentThread() {
    throw new SilentExitException();
}

这在升级到1.3.0里程碑后开始发生

弹簧工具套件

Version: 3.7.0.RELEASE
Build Id: 201506290649

平台:

Eclipse Luna SR2 (4.4.2)

共 (5) 个答案

  1. # 1 楼答案

    我的解决方法:

    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);
            }
        }
    }
    

    我们忽略SilentExitException并不重要,因为devtools只是用一个不太安静的SilentExitException重新启动实例。这个试块会让它安静

    我不得不在类中使用文本匹配,因为SilentExitExceptionSilentExitExceptionHandler中是私有的

    它不能解决你的断点问题

  2. # 2 楼答案

    将属性添加为VM参数:

    -Dspring.devtools.restart.enabled=false
    

    enter image description here

    这样,您就不必更改代码,因为在使用以下命令时就是这样:

    System.setProperty("spring.devtools.restart.enabled", "false");
    
  3. # 3 楼答案

    由于Eclipse on Debug模式已经允许有限的热补丁,我发现重新加载程序在大多数情况下都会适得其反,因此我决定通过以下方式禁用它:

    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

    由于该异常是由重新加载程序引发的,这也解决了这个问题。请注意,您必须使用System.setProperty方法,而不是在application.properties中设置它

  4. # 4 楼答案

    不幸的是,这是新的spring-boot-devtools模块的一个已知问题(请参见https://github.com/spring-projects/spring-boot/issues/3100)。我们使用这个技巧杀死主线程,这样我们就可以用一个可重新加载的版本来替换它。到目前为止,我还没有找到防止触发调试断点的方法

    现在,您可以在Java中切换“未捕获异常时暂停执行”复选框->;调试首选项以防止其发生

  5. # 5 楼答案

    在应用程序中设置此选项。属性文件设置为true

    spring.devtools.restart.enabled=false
    

    另外,如果使用spring云配置服务器,请确保没有支持此功能的属性文件