Spring Boot Developer Tools and App Restart

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

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


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 inEclipse 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, 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(…​).


Important Notes

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

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

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

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

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

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (53) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (8) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (12) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)