首页>代码>基于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);
    }
}
最近下载更多
AlanLi  LV19 5月12日
yang1115  LV2 5月9日
1049066887  LV12 4月14日
涛涛8888  LV6 4月13日
zhanghao943  LV2 4月12日
dengjunjun  LV15 4月11日
做自己的太阳  LV11 4月9日
lo8lukoukoum  LV4 4月7日
wanglinddad  LV55 4月7日
最近浏览更多
sink122406  LV12 昨天
f22m1a2b2  LV16 前天
飃go with wind 5月11日
暂无贡献等级
yang1115  LV2 5月9日
qizl  LV8 5月9日
fff2003  LV6 5月9日
guviva  LV6 5月8日
暂无贡献等级
JQY123  LV3 5月5日
Sul_ALL  LV1 5月5日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友