Breakpoint at “throw new SilentExitException()” in Eclipse + Spring Boot

前端 未结 5 817
Happy的楠姐
Happy的楠姐 2021-01-30 19:35

Every time 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 b

相关标签:
5条回答
  • 2021-01-30 19:54

    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...

    I had to use text matching on the class as the SilentExitException is private in SilentExitExceptionHandler.

    It doesn't solve your problem with the breakpoint...

    0 讨论(0)
  • 2021-01-30 19:57

    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.

    For now, you can toggle the "suspend execution on uncaught exceptions" checkbox in Java -> Debug preferences to prevent it from happening.

    0 讨论(0)
  • 2021-01-30 20:08

    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:

    System.setProperty("spring.devtools.restart.enabled", "false");
    

    Reference: 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.

    0 讨论(0)
  • 2021-01-30 20:10

    Add the property as a VM argument in the configuration like:

    That way you don't have to change your code, as it is the case when using:

    System.setProperty("spring.devtools.restart.enabled", "false");
    
    0 讨论(0)
  • 2021-01-30 20:13

    Try to run devtools at scope runtime:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题