李林
2024-03-18 0d98e9c2d06c5d8b7b6de5ec433a12713744ae6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.yuanchu.mom.config;
 
import cn.hutool.log.Log;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
 
import javax.annotation.Resource;
 
@Configuration
public class OpenFifer extends WebMvcConfigurationSupport {
 
    @Resource
    private FiferConfig fiferConfig;
 
    @Resource
    private PowerConfig powerConfig;
 
    @Resource
    private LogConfig logConfig;
 
    @Value("${file.path}")
    private String filePath;
 
    @Value("${outPath}")
    private String outPath;
 
 
 
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置拦截器访问静态资源
        registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
 
        //设置文件虚拟路径映射
        registry.addResourceHandler("/img/**").addResourceLocations("file:"+filePath+"/");
        registry.addResourceHandler("/outPath/**").addResourceLocations("file:"+outPath);
    }
 
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(fiferConfig).addPathPatterns("/**");
        registry.addInterceptor(powerConfig).addPathPatterns("/**");
        registry.addInterceptor(logConfig).addPathPatterns("/**");
        super.addInterceptors(registry);
    }
}