Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Livereload for assets in Intellij using Spring boot

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?

like image 609
Kaspar Avatar asked Dec 05 '15 12:12

Kaspar


2 Answers

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>
like image 183
Kirill Avatar answered Sep 22 '22 11:09

Kirill


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.

like image 32
Kaspar Avatar answered Sep 21 '22 11:09

Kaspar