首页>代码>基于SpringBoot实现的自习室预订系统>/源代码/springboot3fy99/src/main/java/com/config/InterceptorConfig.java
package com.config;

import org.springframework.context.annotation.Bean;
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 com.interceptor.AuthorizationInterceptor;

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport{
	
	@Bean
    public AuthorizationInterceptor getAuthorizationInterceptor() {
        return new AuthorizationInterceptor();
    }
	
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAuthorizationInterceptor()).addPathPatterns("/**").excludePathPatterns("/static/**");
        super.addInterceptors(registry);
	}
	
	/**
	 * springboot 2.0配置WebMvcConfigurationSupport之后,会导致默认配置被覆盖,要访问静态资源需要重写addResourceHandlers方法
	 */
	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/**")
        .addResourceLocations("classpath:/resources/")
        .addResourceLocations("classpath:/static/")
        .addResourceLocations("classpath:/admin/")
        .addResourceLocations("classpath:/front/")
        .addResourceLocations("classpath:/public/");
		super.addResourceHandlers(registry);
    }
}
最近下载更多
qizl  LV8 5月9日
yiru huang  LV1 5月8日
hyt123456  LV3 5月5日
wanglinddad  LV55 4月29日
203163  LV2 4月25日
xiaozhi丶  LV14 4月22日
jlmarket  LV22 4月22日
最代码官方  LV167 4月21日
最近浏览更多
ZJY1122 昨天
暂无贡献等级
vacalono  LV1 前天
sink122406  LV12 前天
vitowang  LV4 前天
980363152  LV8 5月15日
wwwww816  LV3 5月15日
郭辰曦 5月14日
暂无贡献等级
newcxg  LV1 5月14日
叉烧君 5月14日
暂无贡献等级
AlanLi  LV19 5月12日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友