静态资源访问以及swagger.html 404的配置文件
建了个springboot项目写几个接口,对外提供json格式接口,内部写个页面验证时,发现静态资源404了,好久没写非前后端分离了,故记录一下
thymeleaf:
mode: HTML
prefix: classpath:/templates/
suffix: .html
cache: false
mvc:
static-path-pattern: /static/**
@Configuration
@Component
public class MvcConfig extends WebMvcConfigurationSupport {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/",
"classpath:/META-INF/resources/webjars/springfox-swagger-ui/"};
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**", "/swagger-ui/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
}
}
你应当热爱自由!
作者:Leejk,转载请注明原文链接:https://www.cnblogs.com/leejk/p/16375211.html