| 注:我使用的是外置tomcat启动 注意常见的配置:
 .addPathPatterns("/*");
 .addPathPatterns("/**");
 .addPathPatterns("/user/*");
 .addPathPatterns("/api/*");
 .addPathPatterns("/**").excludePathPatterns("/login");
 有哪些区别
 
 另外spring boot拦截器默认有:
 HandlerInterceptorAdapter
 AbstractHandlerMapping
 UserRoleAuthorizationInterceptor
 LocaleChangeInterceptor
 ThemeChangeInterceptor
 
 复制代码	@Configuration	static class WebMvcConfigurer extends WebMvcConfigurerAdapter {		public void addInterceptors(InterceptorRegistry registry) {			registry.addInterceptor(new HandlerInterceptorAdapter() {				@Override				public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)						throws Exception {					request.getContextPath();					System.out.println("11111111111 Application.WebMvcConfigurer.interceptor");					return true;				}			}).addPathPatterns("/**");		}	}}
复制代码package com.allcam.uas;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.context.web.SpringBootServletInitializer;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;/** *  * <一句话功能简述> <功能详细描述> *  * @author yizhichao * @version [版本号, 2016年7月12日] * @see [相关类/方法] * @since [产品/模块版本] */@SpringBootApplication// same as @Configuration @EnableAutoConfiguration// @Configuration// @ComponentScan// @EnableAutoConfigurationpublic class Application extends SpringBootServletInitializer {	// private static final Logger logger =	// LoggerFactory.getLogger(Application.class);	@Override	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {		return application.sources(Application.class);	}	public static void main(String[] args) {		// File file = new File("log4j2.xml");		// BufferedInputStream in = null;		// try		// {		// in = new BufferedInputStream(new FileInputStream(file));		// final ConfigurationSource source = new ConfigurationSource();		// source.setInputStream(in);		// Configurator.initialize(null, source);		// }		// catch (FileNotFoundException e)		// {		// e.printStackTrace();		// }		SpringApplication.run(Application.class, args);	}	@Configuration	static class WebMvcConfigurer extends WebMvcConfigurerAdapter {		public void addInterceptors(InterceptorRegistry registry) {			registry.addInterceptor(new HandlerInterceptorAdapter() {				@Override				public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)						throws Exception {					request.getContextPath();					System.out.println("11111111111 Application.WebMvcConfigurer.interceptor");					return true;				}			}).addPathPatterns("/**");		}	}}
复制代码@Configurationpublic class WebMvcConfigurer extends WebMvcConfigurerAdapter {	public void addInterceptors(InterceptorRegistry registry) {		registry.addInterceptor(new HandlerInterceptorAdapter() {			@Override			public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)					throws Exception {				System.out.println("222222222222 WebMvcConfigurer.interceptor====");				return true;			}		}).addPathPatterns("/**");	}}
复制代码package com.allcam.uas.filter;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;@Configurationpublic class WebMvcConfigurer extends WebMvcConfigurerAdapter {	public void addInterceptors(InterceptorRegistry registry) {		registry.addInterceptor(new HandlerInterceptorAdapter() {			@Override			public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)					throws Exception {				System.out.println("222222222222 WebMvcConfigurer.interceptor====");				return true;			}		}).addPathPatterns("/**");	}}
 |