spring拦截器,HandlerInterceptorAdapter配置后未生效

编写了拦截器以后,提交请求,拦截器并没有生效,解决办法如下:

spring.xml文件,注意红色字体。

 


 xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

 

 
 
 
 
 
   
     
   
   
  
   
 
 
  
   
   
  

 

   

 

BaseHandlerInterceptor代码如下:

public class BaseHandlerInterceptor extends HandlerInterceptorAdapter{

 @Override
 public boolean preHandle(HttpServletRequest request,
   HttpServletResponse response, Object handler) throws Exception {
  
  System.out.println("^^^^^^^^^^^^^^^^^^^^^^run preHandle ^^^^^^^^^^^^^^^^^^^^^^^^^");
  
  return true;
 }

 @Override
 public void postHandle(HttpServletRequest request,
   HttpServletResponse response, Object handler,
   ModelAndView modelAndView) throws Exception {
 }

 @Override
 public void afterCompletion(HttpServletRequest request,
   HttpServletResponse response, Object handler, Exception ex)
   throws Exception {
 }
}

 

BaseHandlerInterceptor拦截设置未生效是因为没有指定拦截模式,在spring.xml中指定拦截模式后,代码生效。

 

 

 

 

你可能感兴趣的:(spring)