我使用spring 2.5和注释来配置我的spring-mvc web上下文。不幸的是,我无法得到以下工作。我不知道这是一个错误(看起来像)或如果有一个基本的误解如何注释和接口实现子类化工作。
例如,
@Controller
@RequestMapping("url-mapping-here")
public class Foo {
@RequestMapping(method=RequestMethod.GET)
public void showForm() {
...
}
@RequestMapping(method=RequestMethod.POST)
public String processForm() {
...
}
}
工作正常。当上下文启动时,这个处理程序处理的url被发现,一切都很好。
然而,这不:
@Controller
@RequestMapping("url-mapping-here")
public class Foo implements Bar {
@RequestMapping(method=RequestMethod.GET)
public void showForm() {
...
}
@RequestMapping(method=RequestMethod.POST)
public String processForm() {
...
}
}
当我试图拉起url,我得到以下令人讨厌的堆栈跟踪:
javax.servlet.ServletException: No adapter for handler [com.shaneleopard.web.controller.RegistrationController@e973e3]: Does your handler implement a supported interface like Controller?
org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1091)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
但是,如果我改变Bar为一个抽象超类,并有Foo扩展它,然后它再次工作。
@Controller
@RequestMapping("url-mapping-here")
public class Foo extends Bar {
@RequestMapping(method=RequestMethod.GET)
public void showForm() {
...
}
@RequestMapping(method=RequestMethod.POST)
public String processForm() {
...
}
}
这似乎是一个错误。 @Controller注释应该足够标记为一个控制器,我应该能够实现一个或多个接口在我的控制器,而不必做任何其他事情。有任何想法吗?