springboot配置本地⽂件映射路径
1@Configuration
2public class MyBlogWebMvcConfigurer extends WebMvcConfigurerAdapter {
3
4 @Autowired
5private AdminLoginInterceptor adminLoginInterceptor;
6
7public void addInterceptors(InterceptorRegistry registry) {
8// 添加⼀个,拦截以/admin为前缀的url路径
9 registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login").excludePathPatterns("/admin/dist/**").exclu 10super.addInterceptors(registry);
11 }
12
13public void addResourceHandlers(ResourceHandlerRegistry registry) {
14 registry.addResourceHandler("/upload/**").addResourceLocations("file:" + Constants.FILE_UPLOAD_DIC);spring怎么读取配置
15
16super.addResourceHandlers(registry);
17
18 }
19 }
还有直接在配置⽂件中配置
这样也可以映射到本地路径但是 static下⾯的⽂件就访问不到了我更喜欢使⽤第⼀种
resources:
static-locations: file:${web.upload-path},/static/**
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论