spring-bootspring-boot-devtools

Detecting if Spring Boot Devtools are active


Spring Boot has a Devtools package which will turn on useful developer features such as autoreload in an IDE. It will disable itself in the fully packaged application.

Where are the technical details about how Spring Boot Devtools determines whether to become active, and more importantly, how can my application detect at runtime whether Devtools is active?


Solution

  • I believe you are looking for the DevToolsEnablementDeducer which determines if dev tools is enabled within a specific thread based off the current stack and what is excluded by default.

    Also, when built as a jar the spring-boot-maven-plugin will exclude the dependency if configured properly:

    Devtools is automatically excluded by default (you can control that using the excludeDevtools property). In order to make that work with war packaging, the spring-boot-devtools dependency must be set as optional or with the provided scope.

    Likewise, with gradle the recommended way of enabling also does not include when its packaged:

    dependencies {
        developmentOnly("org.springframework.boot:spring-boot-devtools")
    }
    

    This means that if you choose to still include the dependency into your produced jar, then dev tools will then activate based off the existing LocalDevToolsAutoConfiguration which is loaded via the imports.