Spring Boot DevTools在Eclipse中不起作用 [英] Spring Boot DevTools not working in Eclipse
问题描述
但是,当我在静态页面上更改某些内容时,我无法重新加载更改。然后,我打开pom.xml并添加了
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-devtools< / artifactId>
< / dependency>
我重新启动应用程序,但是当我在静态页面上进行一些更改时仍然无法使用。 / p>
有更多的事要做吗?
我的POM.xml
<?xml version =1.0encoding =UTF-8?>
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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> Spring Boot< / description>的演示项目
< parent>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-parent< / artifactId>
< version> 1.5.2.RELEASE< / version>
< relativePath /> <! - 从存储库查找父项 - >
< / 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>
<依赖关系>
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-data-jpa< / artifactId>
< / dependency>
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-thymeleaf< / artifactId>
< / dependency>
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< / dependency>
<依赖关系>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< scope>运行时< / scope>
< / dependency>
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-tomcat< / artifactId>
< scope>已提供< / scope>
< / dependency>
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-test< / artifactId>
< scope> test< / scope>
< / 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>
根据Spring Boot文档:
使用spring-boot-devtools的应用程序将在类路径中的文件更改时自动重新启动。这在IDE中工作时可能是一个有用的功能,因为它为代码更改提供了非常快的反馈循环。默认情况下,将监视指向文件夹的类路径上的任何条目。请注意,某些资源(如静态资源和视图模板)不需要重新启动应用程序。
静态资产不需要重新启动。很可能您的浏览器正在缓存模板并使用缓存版本,而不是请求新的模板。如果您清除浏览器缓存,您应该看到更新的模板。
编辑:
根据您使用的模板技术,您需要在属性文件中设置属性以禁用模板缓存
#Thymeleaf
spring.thymeleaf.cache = false
#FreeMarker
spring.freemarker.cache = false
# Groovy
spring.groovy.template.cache = false
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>
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.
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
这篇关于Spring Boot DevTools在Eclipse中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!