72. Hot swapping

72.1 Reload static content

There are several options for hot reloading. Running in an IDE (especially with debugging on) is a good way to do development (all modern IDEs allow reloading of static resources and usually also hot-swapping of Java class changes). The Maven and Gradle plugins also support running from the command line with reloading of static files. You can use that with an external css/js compiler process if you are writing that code with higher level tools.

72.2 Reload Thymeleaf templates without restarting the container

If you are using Thymeleaf, then set spring.thymeleaf.cache to false. See ThymeleafAutoConfiguration for other Thymeleaf customization options.

72.3 Reload FreeMarker templates without restarting the container

If you are using FreeMarker, then set spring.freemarker.cache to false. See FreeMarkerAutoConfiguration for other FreeMarker customization options.

72.4 Reload Groovy templates without restarting the container

If you are using Groovy templates, then set spring.groovy.template.cache to false. See GroovyTemplateAutoConfiguration for other Groovy customization options.

72.5 Reload Velocity templates without restarting the container

If you are using Velocity, then set spring.velocity.cache to false. See VelocityAutoConfiguration for other Velocity customization options.

72.6 Reload Java classes without restarting the container

Modern IDEs (Eclipse, IDEA, etc.) all support hot swapping of bytecode, so if you make a change that doesn’t affect class or method signatures it should reload cleanly with no side effects.

Spring Loaded goes a little further in that it can reload class definitions with changes in the method signatures. With some customization it can force an ApplicationContext to refresh itself (but there is no general mechanism to ensure that would be safe for a running application anyway, so it would only ever be a development time trick probably).

72.6.1 Configuring Spring Loaded for use with Maven

To use Spring Loaded with the Maven command line, just add it as a dependency in the Spring Boot plugin declaration, e.g.


This normally works pretty well with Eclipse and IntelliJ as long as they have their build configuration aligned with the Maven defaults (Eclipse m2e does this out of the box).

72.6.2 Configuring Spring Loaded for use with Gradle and IntelliJ

You need to jump through a few hoops if you want to use Spring Loaded in combination with Gradle and IntelliJ. By default, IntelliJ will compile classes into a different location than Gradle, causing Spring Loaded monitoring to fail.

To configure IntelliJ correctly you can use the idea Gradle plugin:

buildscript {
    repositories { jcenter() }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:1.2.2.RELEASE"
        classpath 'org.springframework:springloaded:1.2.0.RELEASE'

apply plugin: 'idea'

idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")

// ...

IntelliJ must be configured to use the same Java version as the command line Gradle task and springloaded must be included as a buildscript dependency.

You can also additionally enable ‘Make Project Automatically’ inside Intellij to automatically compile your code whenever a file is saved.