When using Spring without the Spring boot technology, I can start the application with the Tomcat Maven plugin and update my html, css and js without having to restart the server for the changes to take effect in the browser.
Now, when doing this with Spring boot, I will have to do a Make
task in IntelliJ everytime I change something in my static assets, otherwise I just wont see the changes in browser. My Spring Boot application is also using the devtools dependency, and I have the browser connected to the live reload socket when looking.
This configuration still does not show the changes I make in my static files. What do I need to do to get this working?
From my experience static assets in webapp
dir are not available if you build jar
without war
plugin. So i would avoid using this dir. With Spring Boot it is better to use resources/static
folder for your static assets. But you want them to get reloaded while executing Gradle's bootRun
goal or Maven's spring-boot:run
.
To achieve this use the following settings for Gradle:
bootRun {
addResources = true
}
and for Maven:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
It seems that the problem was in the placement of my static assets. I had to put them into a webapp
folder under the main
package. I was following a guide from Spring.io before that advised to put the static assets into resources
package instead.
Now that I stopped using the resources
package, everything works as i want it to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With