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.
If you are using Thymeleaf, then set spring.thymeleaf.cache
to false
. See
ThymeleafAutoConfiguration
for other Thymeleaf customization options.
If you are using FreeMarker, then set spring.freemarker.cache
to false
. See
FreeMarkerAutoConfiguration
for other FreeMarker customization options.
If you are using Groovy templates, then set spring.groovy.template.cache
to false
. See
GroovyTemplateAutoConfiguration
for other Groovy customization options.
If you are using Velocity, then set spring.velocity.cache
to false
. See
VelocityAutoConfiguration
for other Velocity customization options.
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).
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 { mavenCentral() } dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE" classpath 'org.springframework:springloaded:1.2.0.RELEASE' } } apply plugin: 'idea' idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } } // ...
Note | |
---|---|
Intellij must be configured to use the same Java version as the command line Gradle
task and |
You can also additionally enable ‘Make Project Automatically’ inside Intellij to automatically compile your code whenever a file is saved.