SpringBoot默认把类路径下的/static,/public,/resources和META-INF/resources文件下的静态文件映射为了"/",可以直接访问。
自定义访问路径
@Configuration
public class WebMvcAutoConfiguration extends WebMvcConfigurationSupport {
// 配置文件自定义访问路径 也可以通过启动参数修改
@Value("${mole.work}")
private String work;
private static final String FILE_PROTOCOL = "file:///";
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
// 设置外部访问路径
registry.addResourceHandler("/upload/**")
.addResourceLocations(FILE_PROTOCOL + work + "/upload/");
// 设置内部访问路径
registry.addResourceHandler("/assets/**")
.addResourceLocations("classpath:/admin/assets/")
super.addResourceHandlers(registry);
}
}