If we have a look at the Mkyong tutorial for a simple Hello World MVC application.
Now lets say instead of returning a straight hello, the controller instead calls a business logic layer to get what it wants.
@Controller
@RequestMapping("/welcome")
public class HelloController {
private BusinessLogic myBusinessLogic;
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
String text = myBusinessLogic.getMessage();
model.addAttribute("message", text);
return "hello";
}
}
I have two questions here.
- How do I instantiate
myBusinessLogic
? In the exampke mkyong has given, there's no bean configuring theHelloController
. - How do I configure the bean's scope?