App Restart with Spring Boot Developer Tools

The devtools module adds tools that can make the application development easier. This includes automatically apply sensible development-time configuration for features such as caching as caching can be counterproductive during development, auto restarting after changes etc. To include devtools support, we need to add spring-boot-devtools dependency to the build file.

Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”. If you want to ensure that devtools is never included in a production build, you can use the excludeDevtools build property.

 

Auto Restarts and reloads

Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change activities such as saving a file in Eclipse or building the project (Build → Make Project) in Intellij.

The restart works by using two classloaders. Classes that don’t change (e.g. third-party jars) are loaded into a base classloader. Classes that you’re actively developing are loaded into a restart classloader. When the application is restarted, only the restart classloader is thrown away and a new one is created.

By default, changing resources in /META-INF/maven, /META-INF/resources ,/resources ,/static ,/public or /templates will not trigger a restart but will trigger a live reload. If you want to customize exclusions use the spring.devtools.restart.exclude property. If you want to keep defaults and add additional exclusions, use the spring.devtools.restart.additional-exclude property. To restart or reload for changes to files that are not on the classpath, use the spring.devtools.restart.additional-paths property. Use the spring.devtools.restart.exclude property to control triggering a full restart or just a live reload even here.

If you don’t want to use the restart feature you can disable it using the spring.devtools.restart.enabled property, which can be set through applications.properties or a System property before calling SpringApplication.run(…​).

 

Additional notes

  1. Cache options are usually configured in your application.properties file (e.g. spring.thymeleaf.cache property).

  2. You can also start your application via the supported build plugins (e.g. spring-boot-maven-plugin) as long as forking is enabled since

  3. DevTools need an isolated application classloader to operate properly. So, when starting application via supported plugins (e.g. spring-boot-maven-plugin), forking should be enabled.

  4. When triggering a restart, DevTools automatically ignores projects named spring-boot, spring-boot-devtools, spring-boot-autoconfigure, spring-boot-actuator, and spring-boot-starter.

  5. For auto restart and/or reload, you could also consider reloading technologies such as JRebel from ZeroTurnaround, that work by rewriting classes as they are loaded.

  6. The devtools module includes an embedded LiveReload server (which can be disabled) that can be used to trigger a browser refresh when resource is changed. LiveReload extensions are available for browsers.

  7. You can only run one LiveReload server at a time, if you start multiple applications from your IDE only the first will have livereload support.

 

Read more @ http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!