Can any one please explain me the difference between declaring a class with @Controller vs (declaring it with @Scope + define a bean in the applicationContext.xml)
Here is my situation.
Approach 1: declare the class with @Scope and add bean definition in the applicationContext.xml
AbcController.java:
package my.app.controller;
@Scope("singleton")
@RequestMapping(value = "/abc")
public class AbcController {
@RequestMapping(value = "/simulate_abc", method = RequestMethod.GET)
public String getFactorsForSimulate(ModelMap model) {
model.addAttribute("Welcome to the simulations page");
return "simulate_abc";
}
}
applicationContext.xml
<bean id="abcController" class="my.app.controller.AbcController"/>
Approach 2: declare the class with @Controller and no bean definition in applicationContext.xml
package my.app.controller;
@Controller
@RequestMapping(value="/abc")
public class AbcController {
@RequestMapping(value = "/simulate_abc", method = RequestMethod.GET)
public String getFactorsForSimulate(ModelMap model) {
model.addAttribute("Welcome to the simulations page");
return "simulate_abc";
}
}
Here, both the approaches are giving me the expected results (taking me to 'simulate_abc.jsp' with the message attached to the model). I would like to understand, why is Approach1 not failing? Although it has a RequestMapping, since it is not declared as a controller, how come the 'view' is getting resolved? I have a feeling that the Approach1 is wrong, as it does not satisfy 'C' part in the spring 'MVC'.