springboot 读取外部文件

springboot 读取外部文件

external location for image store in Spring Boot 2.0 web app?

之前有个需求是需要有个urlpatren像 staticFiles/xxx.pdf 请求的url 对应服务器端的某个文件夹可以直接访问,

WebMvcConfigurer 需要实现或者继承WebMvcConfigurerAdapter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Configuration

public class MvcConfig extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/btrm/framework/item/static/**")
.addResourceLocations("file:D:\\SVNCODE\\btrm\\")
.setCachePeriod(200);
super.addResourceHandlers(registry);
}

}