【发布时间】:2014-08-04 23:50:10
【问题描述】:
在 Spring Boot 中进行前端部分更新而不重新启动应用程序?
【问题讨论】:
-
你所说的“前端”具体是什么意思? JSP?百里香? HTML + JS 文件?
-
没有 JSP 的 HTML + CSS + JS
标签: java spring-boot spring-tool-suite
在 Spring Boot 中进行前端部分更新而不重新启动应用程序?
【问题讨论】:
标签: java spring-boot spring-tool-suite
我为静态网页和 css 找到的最佳解决方案是 https://stackoverflow.com/a/39334398/6467734 对于加载代码(包括 jsp)而不重新启动服务器,您可以使用 Spring Boot Devtools 依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
【讨论】:
对于 JSP 文件,请尝试设置 server.jsp-servlet.init-parameters.development=true
【讨论】:
将以下内容添加到 src/main/resources/application.properties:
spring.resources.static-locations[0]=file:src/main/resources/static/
spring.resources.static-locations[1]=classpath:/static/
“文件:”会导致刷新浏览器时重新加载内容
或者,可以在运行时发现文件资源位置并以编程方式添加。 我希望这会有所帮助。
【讨论】:
在 Intellij IDEA 中以 Debug 模式运行您的项目,您将获得相同的效果。
或者将你的静态外部化。
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
private String extStaticPath = "/var/www/site1/";
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations(extStaticPath)
.setCachePeriod(0);
}
}
【讨论】:
您可以在 Spring Boot 中尝试 developer tools。每当类路径上的文件更改时,使用 spring-boot-devtools 的应用程序将自动重新启动。更多信息如何工作here
【讨论】:
我是 Eclipse 用户(通过 Spring Tool Suite),如果应用程序在调试模式下运行,我在重新加载静态内容方面从来没有任何问题。只需右键单击主类和“Debug As->Java App”(或“Spring Boot App”,都一样)。您还必须确保将工作区配置为“自动构建”,但据我所知,这是默认设置。
我无法为其他 IDE 的用户提供这样具体的建议,但我确信它们都具有相同的功能。
【讨论】: