Announcement Announcement Module
Collapse
No announcement yet.
Intercepting requests with a HandlerInterceptor ( Spring 3.1.1 ) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Intercepting requests with a HandlerInterceptor ( Spring 3.1.1 )

    I want to intercept all request using HandlerInterceptor as guideline from here
    http://static.springsource.org/sprin...handlermapping

    The root URL: http://localhost:8080/hello-world-web/ doesn't work in 3.1.1
    i put http://localhost:8080/hello-world-web/login also not working

    but i getting error as below :
    Code:
    Stacktrace: javax.servlet.ServletException: No adapter for handler [public java.lang.String com.example.controller.LoginController.displayLogin(javax.servlet.http.HttpServletRequest)]: Does your handler implement a supported interface like Controller?
    LoginController
    Code:
    @Controller
    public class LoginController extends AbstractController{
    
        @RequestMapping(value = "/login", method = RequestMethod.GET)
        public String displayLogin(HttpServletRequest request) {
         
            return "/login";
        }
    }
    servlet.xml
    Code:
    <bean id="interceptor_1" class="com.example.interceptor.Interceptor_1"/>
    	  <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="interceptor_1"/>
                </list>
            </property>
        </bean>
    Interceptor_1
    Code:
    public class Interceptor_1 extends HandlerInterceptorAdapter{
    	
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       
        	String url = request.getPathInfo();
            System.out.println("url : " + url);
     
        	return true;
    
        }
    
    }
    I remove the AnnotationMethodHandlerAdapter and DefaultAnnotationHandlerMapping as suggested from
    http://forum.springsource.org/showth...dapter+handler but still having the same error

  • #2
    Don't extend AbstractController as that is deprecated and that way you are mixing interface and annotation based controllers in a single controller, not something you should do.

    I remove the AnnotationMethodHandlerAdapter and DefaultAnnotationHandlerMapping
    Which is good as that conflicts with the RequestMappingHandlerMapping however next to the RequestMappingHandlerMapping you should also add the RequestMappingHandlerAdapter.

    Comment

    Working...
    X