在网上找了好多,基本上都一个样,按照一步一步来,都是无效,下面是我的配置:Config:importcom.example.demo.interceptor.OneInterceptor;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.InterceptorRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;@ConfigurationpublicclassInterceptorConfigimplementsWebMvcConfigurer{@OverridepublicvoidaddInterceptors(InterceptorRegistryregistry){registry.addInterceptor(newOneInterceptor()).addPathPatterns("/**");}}OneInterceptor:importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.stereotype.Component;importorg.springframework.web.servlet.HandlerInterceptor;importorg.springframework.web.servlet.ModelAndView;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;@ComponentpublicclassOneInterceptorimplementsHandlerInterceptor{privateLoggerlogger=LoggerFactory.getLogger(OneInterceptor.class);@OverridepublicbooleanpreHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objectobject)throwsException{logger.debug("拦截。。。");returnfalse;}@OverridepublicvoidpostHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler,ModelAndViewmodelAndView){System.err.println("post");}@OverridepublicvoidafterCompletion(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler,Exceptionex){System.err.println("after");}}无论访问什么路径都不会走拦截器,不知道哪里配置错了,求大神解答!
慕虎7371278
相关分类