I am developing a RESTful service using Spring 3.0 running on Tomcat Apache 6.0. The DispatcherServlet Spring dispatcher is configured to "/ spring / *". The Spring servlet handles multiple clients and has many controllers in the application. I am adding a new controller for the REST service. I want all my controller classes to have an identifier prefix like "ws" (web service) so that the entire URL of the resource looks like this: http://<server>:<port>/<context>/spring/ws/service1
The only way I found with Spring annotation is to use @RequestMapping as follows:
@Controller @RequestMapping("/ws/service1") public class Service1 { @RequestMapping(method=RequestMethod.GET) @ResponseBody public String getHtml() { ... } .... }
But since I have dozens of classes, I donβt want to put the prefix β/ wsβ in each class. So, if another developer adds a new service, he should not forget to put this prefix, and also if we decided to change the prefix name from "/ ws" to something else, I do not need to change all the files. I found that the @RequestMapping annotation applies only to methods or classes, not to the package level.
Is there any way I can configure so that all my REST controllers are accessible with a prefix?
Please note that I cannot change the URL of the web.xml URL for the Spring servlet, as there are other controllers that work with this URL.
Shreerang
source share