- 实现
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
接口
- 重写
void addResourceHandlers(ResourceHandlerRegistry registry)
方法
- 添加资源映射
public class DeployServerApplication implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 配置静态资源映射
registry.addResourceHandler("/**/*.html", "/**/*.css", "/**/*.js")
// 资源字符串支持标准的java url格式,分别为 classpath: 或 file:
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}