Results 1 to 2 of 2

Thread: Same relative @RequestMapping but different absolute paths

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Default Same relative @RequestMapping but different absolute paths

    Hello all,

    I am trying to map multiple dispatch servlets to different contexts as such:

    /api/* -> DispatchServlet1
    /service/* -> DispatchServlet2

    absolute paths:
    /api/resources -> package1.class1.method1
    /service/resources -> package2.class2.method1


    Code:
    <servlet-mapping>
    	<servlet-name>DispatchServlet2</servlet-name>
    	<url-pattern>/service/*</url-pattern>
    </servlet-mapping>
    	
    <servlet-mapping>
    	<servlet-name>DispatchServlet1</servlet-name>
    	<url-pattern>/api/*</url-pattern>
    </servlet-mapping>
    Within DispatchServlet1 servlet-context file, I configured to do component-scanning in package1 which has Class1 definition as so:

    Code:
    @Controller
    public class Class1 {
      @RequestMapping(value = "/resources", method = RequestMethod.GET) 
       public ResponseEntity<String> method1() {...}
    }
    Within DispatchServlet2 servlet-context file, I configured to do component-scanning in package2 which has Class2 definition as so:

    Code:
    @Controller
    public class Class2 {
      @RequestMapping(value = "/resources", method = RequestMethod.GET) 
       public ResponseEntity<String> method1() {...}
    }
    However, with the above configuration, I get the following exception:
    Code:
    Cannot map handler 'class2' to URL path [/resources]: There is already handler of type [class package2.Class2] mapped.
    How can I fix the above? Use a non-DefaultAnnotationHandlerMapping?

    Thanks,
    Chandra

  2. #2
    Join Date
    Feb 2013
    Posts
    2

    Default

    I found the problem, basically, one of the dispatch servlet is scanning all the packages and is the cause of conflict.

    Thanks,
    Chandra

    PS: Mods, please delete this thread. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •