项目访问不到html中引用的静态文件
05:45:50.955 [http-nio-8085-exec-4] WARN org.springframework.web.servlet.PageNotFound - No mapping for GET /property/templates/system/js/jquery-3.5.1.min.js
参考:https://blog.csdn.net/qq_37281398/article/details/107905807
对于静态页面需要直接放行!
<resources mapping="/resources/**" location="/resources/" />
<resources mapping="/images/**" location="/images/" />
<resources mapping="/js/**" location="/js/" />
再次遇到这个问题,好像在application.xml中的配置是不生效的,加了配置类才生效
@Configuration
public class WebConfig implements WebMvcConfigurer {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/templates/", "classpath:/resources/templates/"};
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
}
}
实际配置:问题解决:
# 引擎模板配置
thymeleaf:
cache: false # 关闭缓存
mode: LEGACYHTML5 # 去除htm5严格校验
prefix: classpath:/templates/system/ # 指定 thymeleaf 模板路径
encoding: UTF-8 # 指定字符集编码
suffix: .html
mvc:
# static-path-pattern: /static/** # js ,css 等静态文件路径
static-path-pattern: /templates/** # js ,css 等静态文件路径
其中html中的 ./ 代表的含义待考证:
修改context-path :/property
之后出现访问不了;
修改context-path: /
又可以了: