继承WebMvcConfigurerAdapter 类,添加 上文写的拦截类
具体代码如下:
package com.hcmony.web.interceptor; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * <h3>权限拦截</h3> * <p></p> * @author hcmony * @since V1.0.0, 2017/12/15 18:13 */ @Configuration public class InterceptorConfigurer extends WebMvcConfigurerAdapter { @Override public void addInterceptors(InterceptorRegistry registry) { // 多个拦截器组成一个拦截器链 // addPathPatterns 用于添加拦截规则 registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/*/*"); // excludePathPatterns 用户排除拦截 //registry.addInterceptor(new AuthInterceptor()).excludePathPatterns("/"); super.addInterceptors(registry); } }