36 lines
1.0 KiB
Java
36 lines
1.0 KiB
Java
package com.bao.dating.config;
|
|
|
|
|
|
import com.bao.dating.interceptor.TokenInterceptor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
/**
|
|
* WebMvc配置类
|
|
* @author KilLze
|
|
*/
|
|
@Configuration
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
@Autowired
|
|
private TokenInterceptor tokenInterceptor;
|
|
|
|
/**
|
|
* 添加拦截器到Spring MVC配置中
|
|
* @param registry 拦截器注册中心
|
|
*/
|
|
@Override
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
//注册自定义拦截器对象
|
|
registry.addInterceptor(tokenInterceptor)
|
|
// 拦截所有请求
|
|
.addPathPatterns("/**")
|
|
// 忽略的接口
|
|
.excludePathPatterns(
|
|
"/user/login"
|
|
);
|
|
}
|
|
}
|