首页>代码>基于SpringBoot+Vue实现的家具电子商城系统>/源代码/springbooth4q2o/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);
    }
}
最近下载更多
hdf999  LV12 11月18日
JulyMagnolia  LV5 4月22日
天天吃面  LV27 3月19日
段池卿  LV5 2月6日
ruozizz  LV3 1月9日
AABBCCDD123  LV2 1月8日
zolscy  LV24 2024年11月23日
15953970869  LV6 2024年11月10日
最代码官方  LV168 2024年11月2日
最近浏览更多
hpr1234511  LV3 昨天
1124215637  LV1 11月18日
hdf999  LV12 11月18日
azoker 11月10日
暂无贡献等级
心印语  LV9 11月6日
筱洋1616  LV9 11月2日
khmumuno 10月25日
暂无贡献等级
暂无贡献等级
chokkint  LV12 10月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友