0

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.

  1. How do I instantiate myBusinessLogic? In the exampke mkyong has given, there's no bean configuring the HelloController.
  2. How do I configure the bean's scope?
dwjohnston
  • 11,163
  • 32
  • 99
  • 194
  • You can autowire your service bean here business logic bean in the controller. You can use this for referance : www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial – Dipen Adroja Apr 13 '15 at 03:14
  • @DipenAdroja - The problem I have with this solution, is that I then have this problem for my unit tests. http://stackoverflow.com/questions/4377699/spring-contextconfiguration-how-to-put-the-right-location-for-the-xml – dwjohnston Apr 15 '15 at 02:09

0 Answers0