Spring Boot DevTools not working in Eclipse
Asked Answered
B

9

16

I built an application using Spring, JPA, MySQL and Web. I developed a static page in template folder normally and it works.

But, when I change something on static page, I can't reload it with changes. Then, I open the pom.xml and added

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>

I restart the application, but, still not working when I make some changes on the static page.

Is there something more to do?

My POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.engsoftware</groupId>
    <artifactId>cobranca</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>Cobranca</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
Bascom answered 31/3, 2017 at 18:13 Comment(3)
Try running it from the command line mvn spring-boot:run , it's working for me in STS and from command line as well with the same POM.Panelboard
Do you have the LiveReload extension installed?Mofette
I have LiveReload extension on Chrome installed. But still not working. If I open in a different browser, show the same page without any changes. I tried clean the cache of browser too, but no success. I clean and install Maven and nothing.Bascom
B
15

I followed this article https://github.com/spring-projects/spring-boot/issues/7479

So, to devtools works, you must add:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    <scope>runtime</scope>
</dependency>

The secret is add Optional True and Scope runtime.

Bascom answered 13/8, 2017 at 9:32 Comment(0)
T
41

In your eclipse top menu your Project -> Build Automatically ON ?

Topflight answered 29/6, 2018 at 18:56 Comment(4)
You might want to add some more detail as to what that setting does and why it would solve the issue. As it stands right now it is not a lot more than a clarification request that should go into a comment.Prudery
Perfect. ThanksBradwell
How on Earth didn't I think of that before!? It's been bugging me for a couple of days! I tried almost every SpringBoot related setting... didn't occur to me to check if I had accidentally disabled the automatic build in Eclipse - sigh... Thanks!Cubitiere
Thanks a lot. I always forget this.Exhale
B
15

I followed this article https://github.com/spring-projects/spring-boot/issues/7479

So, to devtools works, you must add:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    <scope>runtime</scope>
</dependency>

The secret is add Optional True and Scope runtime.

Bascom answered 13/8, 2017 at 9:32 Comment(0)
T
9

This question is already answered, but for me didn't worked exactly as the accepted answer or other answers tells.

I've got devtools working in the following way:

1) Using the devtools dependency as following:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    <scope>runtime</scope>
</dependency>

2) Deleting the Spring Maven cache, in Linux it would be:

rm -rf ~/.m2/repository/org/springframework/*

3) Back into Eclipse, pressing Alt+F5 and forcing to clean the project re-downloading every dependency from Maven to your cache.

The key is to set the optional flag to true into the devtools' dependency AND wiping the Maven cache.

Hope this is helpful to someone.

Twinkle answered 29/8, 2018 at 18:7 Comment(2)
Step 2 solved it for me. There seems to have been some kind of cache which caused that the devtools was not loaded properly.Motoring
Your "2)" step helped me, too.Defalcation
M
5

In addition to the answers given above, you also need to have Build Automatically enabled in Eclipse. It doesn't matter to Dev Tools if your java files are updated, the only thing it looks for is the .class, resource file changes.

For IntelliJ, refer to the diagram below.

enter image description here

Mikkel answered 11/8, 2019 at 0:48 Comment(0)
J
1

According to the Spring Boot docs:

Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change. This can be a useful feature when working in an IDE as it gives a very fast feedback loop for code changes. By default, any entry on the classpath that points to a folder will be monitored for changes. Note that certain resources such as static assets and view templates do not need to restart the application.

http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools-restart

Templates and static assets do not need a restart. Most likely your browser is caching the templates and using the cached version instead of requesting the new template. If you clear the browsers cache, you should see the updated template.


EDIT:

Depending on your template technology you're using, you will need to set a property in your properties file to disable the template cache

# Thymeleaf
spring.thymeleaf.cache = false

#FreeMarker
spring.freemarker.cache = false

#Groovy
spring.groovy.template.cache = false

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html#howto-reload-static-content

Jurisprudence answered 31/3, 2017 at 18:50 Comment(3)
I have LiveReload extension on Chrome installed. But still not working. If I open in a different browser, show the same page without any changes. I tried clean the cache of browser too, but no success. I clean and install Maven and nothing.Bascom
@JohnMendes In Eclipse, have you tried a clean and rebuild of the project after you added the devtools dependency? Also what are you using for templates?Jurisprudence
Just looked at your pom and saw the dependency for Thymeleaf. You'll need to set the Thymeleaf template cache to false in you properties file. spring.thymeleaf.cache=falseJurisprudence
L
0

Even after trying above mentioned answers, if it is still not working just try enabling build automatically for the project in eclipse. It worked for me after that.

Lightproof answered 14/3, 2018 at 18:26 Comment(0)
C
0

This worked for me. Add the below line in application.properties file,

spring.devtools.restart.enabled=true
Congelation answered 22/9, 2018 at 16:20 Comment(0)
F
0

For my case the problem is on Eclipse's Java Build Path (Right Click Project > Properties > Java Build Path > Source Tab), end up there is an error on one of the source folder which doesn't exist at all. After I remove that folder from build path, it started auto build.

Fenske answered 12/7, 2021 at 6:33 Comment(0)
C
0

The other reason for someone with the same issue is because under the PARENT tag for Spring-Boot-Starter-Parent Artifact Id, the version is already mentioned, so incase you have copied the dependency from any other source that the Spring Starters Project, you don't need to mention the version explicitly in the Spring DevTools Dependency. So just remove the Version & Version Tag from it.

enter image description here

Carthage answered 17/5, 2022 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.