首页>代码>基于SpringBoot+Vue图书个性化推荐系统的设计与实现>/源代码/服务端代码/springbootxs5o6/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);
    }
}
最近下载更多
BIMENGCH  LV1 3月25日
zolscy  LV24 2024年11月24日
momomo228  LV2 2024年11月21日
lilong007  LV23 2024年8月28日
mlml123  LV6 2024年8月20日
java小书童  LV18 2024年7月9日
微信网友_7044194812350464  LV8 2024年7月6日
zxc123zdq  LV15 2024年7月2日
微信网友_7042775796502528  LV1 2024年6月18日
sweetlove  LV20 2024年6月12日
最近浏览更多
AniyaKKbi 8月28日
暂无贡献等级
酷酷的轲  LV10 8月26日
38735466  LV11 8月18日
denliv_hui  LV14 8月7日
ewan007  LV30 7月2日
暂无贡献等级
newhaijun  LV16 6月7日
lkke23047  LV1 5月26日
梁小贤  LV1 5月22日
木子520  LV12 5月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友