John Mendes
John Mendes

Reputation: 789

Spring Boot DevTools not working in Eclipse

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>

Upvotes: 16

Views: 45158

Answers (9)

Syed Aaqib Hussain
Syed Aaqib Hussain

Reputation: 139

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

Upvotes: 0

Newbie
Newbie

Reputation: 1714

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.

Upvotes: 0

user204069
user204069

Reputation: 1081

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

Upvotes: 43

Durja
Durja

Reputation: 667

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

Upvotes: 5

Ezhil vikraman
Ezhil vikraman

Reputation: 11

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

spring.devtools.restart.enabled=true

Upvotes: 0

gorcajo
gorcajo

Reputation: 580

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.

Upvotes: 9

ABC
ABC

Reputation: 55

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.

Upvotes: 0

John Mendes
John Mendes

Reputation: 789

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.

Upvotes: 16

Jason White
Jason White

Reputation: 5813

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

Upvotes: 1

Related Questions