Spring Boot DevTools not working in Eclipse

ぐ巨炮叔叔 提交于 2019-12-22 04:19: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>

回答1:


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




回答2:


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.




回答3:


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.




回答4:


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




回答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.




回答6:


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.




回答7:


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

spring.devtools.restart.enabled=true


来源:https://stackoverflow.com/questions/43147157/spring-boot-devtools-not-working-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!