Announcement Announcement Module
Collapse
No announcement yet.
Same relative @RequestMapping but different absolute paths Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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!

    Comment

    Working...
    X