开发环境用如下配置即可
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/