Springboot+thymeleaf 在idea开发工具里运行可以访问到templates里的html和静态文件,Maven打war包,放Tomcat里运行就找打不到static静态文件,这是为什么呢?tomcat启动后 静态文件报404。
spring:
thymeleaf:
cache: false
prefix: classpath:/templates/
suffix: .html
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/********?characterEncoding=UTF-8
username: root
password: root
web:
resources:
static-locations: classpath:/static/**
mvc:
static-path-pattern: /static/**
tomcat资源目录下看下是否有静态资源文件。
点开你的war包,找里面的静态文件进行比对看看那些未加载的资源是不是没有打包进去呀
404的一直都是这几个文件是不
看看你pom中打包插件对静态资源的设置
webResources -> resource -> include
搞定了,漏了这个
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}