- 使用注解 @Configuration 配置拦截器
- 继承 WebMvcConfigurerAdapter
- 重写 addInterceptors 添加需要的拦截器地址
- 具体实现
package com.worksplaza.edu.online.configuration;
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.WebMvcConfigurer;
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
@Bean
public SessionInterceptor sessionInterceptor() {
return new SessionInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(sessionInterceptor())
.addPathPatterns("/**").excludePathPatterns("/crossdomain.xml")
.excludePathPatterns("/weixin/")
.excludePathPatterns("/wechat/notify");
}
}
网友评论