0

How View resolver determine which controller to load when more than one @Controller exist.

I am learning Spring from Scratch, as per my instructor she says, we need to have only one Controller class with @Controller annotation. what if I have more than one class with a @Controller annotation and how ViewResolver determines which controller class to load, as Spring is singelton and only one controller class exist.

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
  • http://stackoverflow.com/help/how-to-ask Please read how to ask a question. Post some code and highlight the specific issues you are facing. If this is a homework question then you should really be asking your instructor how to do it. – Tim Rutter Mar 30 '16 at 07:17
  • Your basics are really weak. First, think before you ask/speak. View Resolver, as the name specifies, just resolves views or simply provides the 'visual layout page' like .jsp files. And it is DispatcherServlet which determines the controller based on the 'path' as depicted by RequestMapping annotation. – Tahir Hussain Mir Mar 30 '16 at 09:32

2 Answers2

0

It is not view resolver that determines which controller to load: it is instead the DispatcherServlet that does that. What View resolver does is to match String-based view names to actual View types. In order to match more than one controller you can use servlet mapping to define services and endpoints.

If you browse to http://docs.spring.io/autorepo/docs/spring/3.2.x/spring-framework-reference/html/mvc.html, you will find an in depth description of how things work. structure

Community
  • 1
  • 1
LoreV
  • 575
  • 5
  • 25
0

It does not determine which @Controller to load, it loads all @Controller which is configured scanned packages

VinhNT
  • 1,091
  • 8
  • 13