According to Reload static content hot reloading of FreeMarker templates should work in the IDE as long as spring.freemarker.cache=false
. This does not work in IntelliJ (v 15.0.3) neither in debug nor in run mode.
From the command line spring-boot:run
doesn't work either which I guess is expected. What's more surprising is that adding devtools
has no impact. The only way to get it to work is to add this to the pom build plugin:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
This is hardly intuitive. For once it should be documented clearly in the "Reload static content" section. In effect though devtools
IMO is not working as advertised.
Comment From: snicoll
I am confused, I thought we already had that discussion.
Both work for me, I've shared a video that demonstrates how it works with devtools. I haven't demonstrated without devtools and spring.freemarker.cache=false
in the video but I just tried and it does work as well (run or debug).
In both cases, Spring Boot works with the classpath (obviously) so it can't see anything you change in src/main/resources
until the classpath is updated. So you need to trigger that. In Eclipse, you need to save your changes and when you do, an incremental compilation is invoked. In IntelliJ IDEA, there is no such thing as save and your files are saved automatically. You need to trigger an incremental compilation (using the Build -> Make Project action). Both are a signal that you want devtools to do "something". If you only change something devtools consider to be "non code" related, it will just trigger livereload and won't restart your app.
If you are a former eclipse user, I would advise to remap the "Make Project" action to whatever shortcut you use in Eclipse to save your files. Some people are lobbying for an automatic compilation in IntelliJ IDEA so you could try that as well if you want: 1. Help -> Actions -> Registry - compiler.automake.allow.when.app.running = checked 2. Preferences -> Compiler -> Make Project Automatically = checked
Let me know if I am missing something.
Comment From: wilkinsona
At the very least, we need to amend this entry in the release notes:
The Spring Boot Maven plugin no longer adds src/main/resources directly to the classpath when using spring-boot:run. If you want live, in-place editing we recommend using Devtools. The addResources property can be set in your pom.xml if you want to restore Spring Boot 1.2. behavior.
Specifically, "if you want live, in-place editing we recommend using Devtools". That only works if you're using an IDE and have something updating the classpath for you. If you're using mvn spring-boot:run
and a text editor for front-end development, DevTools won't help you.
Comment From: snicoll
Andy and I had an extensive discussion that lead to the creation of #5136
Comment From: snicoll
I've also created #5137 to improve the out-of-the-box experience of devtools with the build plugins
Comment From: rstoyanchev
First of all apologies for any confusion caused! That was not my intention.
That said my own confusion has to do with unlearning learned behavior from Boot 1.2 for running in exploded form and editing resources for instant “hot” reload. I don't argue against the change. I'm only saying that taking away the experience of saving an HTML template and hitting F5 cannot go unnoticed. On the other hand a release note such as this can easily go unnoticed.
Great to see #5136 by the way, as it is currently I hardly ever use "Make Project". Not only is it not intuitive to do make the project for a static resource change but it's unusual in terms typical workflow when working inside IntelliJ.
Yes I know it's been mentioned I can change preferences and it's arguably something IntelliJ should do but we are talking developer experience. For that matter if the Static Reload Content section explained in clear terms that Boot monitors the classpath and in IntelliJ that means you need to do Make Project or change your preferences I think much of the confusion would be eliminated. So I guess a lot comes down to improving the docs.
Comment From: RichardBradley
If you want "hot" reload without needing to rebuild the project (for example, for files edited outside of your IDE, such as by npm
), I found that adding a "file:" entry to the spring.resources.static-locations
will do that, i.e.
spring.resources.static-locations[0]=file:my-module/src/main/resources/public/
spring.resources.static-locations[1]=classpath:/public/
This will have no effect on live servers, as they do not have a "src" directory.
Comment From: Slayug
If you want "hot" reload without needing to rebuild the project (for example, for files edited outside of your IDE, such as by
npm
), I found that adding a "file:" entry to thespring.resources.static-locations
will do that, i.e.
spring.resources.static-locations[0]=file:my-module/src/main/resources/public/ spring.resources.static-locations[1]=classpath:/public/
This is deprecated now, you may use:
spring.web.resources.static-locations[0]=file:./src/main/resources/public/
spring.web.resources.static-locations[1]=classpath:/public/
Comment From: shawaalsaif
@RichardBradley im able to load images dynamically locally using resources handler but Im not able to load uploaded images on live server. my path was set to src/main/resources/images/ but as you said there is no src directory what changes should i make in the path?