Search code examples
springspring-mvcurl-mapping

Can i use Spring's @RequestMapping and BeanNameUrlHandlerMapping in conjuntion with each other to map a URL to method?


What I would like to do is have a common Service class which has various methods such as "search" "retriveByID" etc. Ideally this class would consume the service parameters and populate a request object and hand off to the appropriate data source handler.

I want to instantiated a service class as a Spring bean with different request handlers depending on the domain object being searched. Then using bean BeanNameUrlHandlerMapping invoke a different Service class based on the URL.

<bean name="/sequence/*" class="org.dfci.cccb.services.SearchServiceImpl">
    <property name="searchHandler">
     ....

My problem is that when i try to do this I can't use method level RequestMapping annotations to select the appropriate method of the service class.

@RequestMapping("*/search/")
QueryResult search(...

Alternatively is it possible to inject annotation values through bean definitions?

UPDATE There is also a Springsource article on this topic: http://blog.springsource.com/2008/03/23/using-a-hybrid-annotations-xml-approach-for-request-mapping-in-spring-mvc/


Solution

  • Was very surprised to learn that it actually works. Just remove the trailing slash:

    @RequestMapping("*/search") 
    

    And this works too:

    @RequestMapping("search")