My project includes older un-annotated controllers together with newer annotation-based controllers.
I am using the latest Spring jars (3.0.5) and in my dispatcher-servlet.xml there’s <mvc:annotation-driven />.
The problem is that <mvc:annotation-driven /> causes the request mapping (through the name property of the controller beans in the dispatcher-servlet.xml) to my un-annotated controllers not to work… each time I direct the request to an un-annotated controller I am getting an error message such as:
org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/some_path/some_page.htm] in DispatcherServlet with name 'dispatcher'
How can I keep the un-annotated controllers as they are but tell spring to recognize their (old style) mapping?
I am looking for solutions with minimum change to the Java code of the controllers that I already have.
Thanks!
When you add
<mvc:annotation-driven />to your config, it replaces the default set of handler mappings and handler adapters, and those defaults were the ones that handled the old-style controllers.You have 2 options. First thing to try is to remove
<mvc:annotation-driven />. You can still use annotated controllers without this. It does add extra features like Jackson JSON support, but if you don’t need those extra features, then you don’t need it. So try your app without<mvc:annotation-driven />and see if it still works.Failing that, you can reinstate the mappings and adapters for your old controllers. You didn’t say how your controllers used to have their URLs mapped, but try adding these to your config:
If you used
SimpleUrlHandlerMapping, then that should be working already.You also need to add the
HandlerAdapterback in:Don’t just add these in blindly. Try them individually, and see what the minimal set is to get your old controllers working alongside the new ones.