Spring MVC is structured to handle state management, workflow and validation. It is an application of the Model-View-Controller pattern. As with all things Spring, it follows the principles of loose coupling and flexibility. When a request is made, it reaches the DispatcherServlet whose role is to forward the request to the relevant Spring MVC controller, it is the controller that processes the request. In this article we will look in depth in what a Spring Controller does when it processes input.
In my previous post, I showed you how to create a HomeController for our home page in your application. You might have noted that there was little code that linked your HomeController with Spring that was included. It is simply a plain old java object (POJO). In this tip, we will look at unit testing your controller. Unit testing your controller will be very easy since a POJO doesn’t need you to mock any Spring or other specific objects. I will create a test object using standard naming conventions,
When you work with Spring MVC, after configuring the Dispatcher Servlet in order to build an application you need to do the following:
Define controllers that invoke business logic and create a ModelAndView object.
Visualization component like JSP, Velocity or FreeMarker.
Annotation configuration or XML to wire the components together
The first thing that you will most likely do is to define a home page controller. Spring provides a number of controllers to use