Using ControllerClassNameHandlerMapping with @Controller and extending AbstractController

Posted by whiskerz on Stack Overflow See other posts from Stack Overflow or by whiskerz
Published on 2010-03-18T13:05:51Z Indexed on 2010/03/18 13:11 UTC
Read the original article Hit count: 304

Filed under:
|
|

Hey there,

actually I thought I was trying something really simple. ControllerClassNameHandlerMapping sounded great to produce a small spring webapp using a very lean configuration. Just annotate the Controller with @Controller, have it extend AbstractController and the configuration shouldn't need more than this

<context:component-scan base-package="test.mypackage.controller" />
<bean id="urlMapping" class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

to resolve my requests and map them to my controllers. I've mapped the servlet to "*.spring", and calling

<approot>/hello.spring

All I ever get is an error stating that no mapping was found. If however I extend the MultiActionController, and do something like

<approot>/hello/hello.spring

it works. Which somehow irritates me, as I would have thought that if that is working, why didn't my first try? Does anyone have any idea? The two controllers I used looked like this

@Controller
public class HelloController extends AbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView modelAndView = new ModelAndView("hello");
    modelAndView.addObject("message", "Hello World!");
    return modelAndView;
    }
}

and

@Controller
public class HelloController extends MultiActionController {
public ModelAndView hello(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView modelAndView = new ModelAndView("hello");
    modelAndView.addObject("message", "Hello World!");
    return modelAndView;
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about spring-mvc