liuxiaolong
2019-05-06 a7bed6b4cfecd61ec153818945f982c5bb796b98
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
package com.cloud.attendance.config;
 
import com.cloud.attendance.filter.AuthorizationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
//@EnableWebMvc
@Configuration
public class AdapterConfig extends WebMvcConfigurerAdapter {
 
    @Bean
    AuthorizationInterceptor authorizationInterceptor() {
        return new AuthorizationInterceptor();
    }
 
 
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        registry.addInterceptor( authorizationInterceptor()).excludePathPatterns("/**/noauth/**", "/favicon.ico","/**/swagger-resources/**",
                "/**/webjars/**", "/v2/**", "/swagger-ui.html/**","/static/**","/loginData/api-u/**"
                ,"/index.html")
                .addPathPatterns("/**");
        super.addInterceptors(registry);
    }
 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**","/index.html")
                .addResourceLocations("classpath:/static/","classpath:/index.html");
        registry.addResourceHandler("/swagger-ui.html")        ///  wp 添加 swagger-ui
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")              ///  wp 添加 swagger-ui
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
}