spring-boot 使用thymleaf修改页面不重启生效

开发环境用如下配置即可

spring.mvc.static-path-pattern=/static/**

# Templates reloading during development
spring.thymeleaf.prefix=file:src/main/resources/templates/
spring.thymeleaf.cache=false


# Static resources reloading during development
spring.resources.static-locations=file:src/main/resources/static/

  • spring.web.resources.static-locations是后续配置,旧版Springboot的配置项为:spring-resources-static-locations;在2.2.5版本之后,旧版本配置已经失效。

spring.resources.cache-period=0

其他环境或打包运行:

spring.thymeleaf.prefix=classpath:/templates/
spring.web.resources.static-locations=classpath:/static/

完整thymleaf配置:

<properties>  
    <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
    <thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>
</properties>

server.servlet.multipart.enabled=true
server.servlet.multipart.max-file-size=50MB
server.servlet.multipart.max-request-size=100MB


server.mvc.servlet.path=/
spring.mvc.static-path-pattern=/static/**


spring.thymeleaf.cache=true
spring.thymeleaf.check-template=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.suffix=.html


spring.web.resources.static-locations=classpath:/static/

版权声明:本文为ssseeelll原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。