robinson.L
robinson.L

Reputation: 83

about Spring3 MVC Controller's @RequestMapping

Can't one RequestMapping name,such as @RequestMapping("/console"), be used in several class? I mean Controller's class mapping. BTW, method's requestmapping will be diferent.

Upvotes: 1

Views: 674

Answers (1)

Ben J
Ben J

Reputation: 5871

For what it's worth, I recommend that you don't do what you're trying to do as it can be difficult to maintain. In my opinion, organisation of URLs / mappings is important in the same way you organise your code.

The documentation @RequestMapping suggests the same:

It is strongly recommended to co-locate related handler methods into the same bean.

But regarding your question - I don't believe that this is possible. Again, from the documentation of @RequestMapping (emphasis is my own):

Method-level mappings are only allowed to narrow the mapping expressed at the class level (if any). HTTP paths / portlet modes need to uniquely map onto specific handler beans, with any given path / mode only allowed to be mapped onto one specific handler bean (not spread across multiple handler beans).

Upvotes: 2

Related Questions