What is Spring Web MVC Framework ? List its key features.

 ● The Spring Web Model-View-Controller (MVC) framework is designed around a DispatcherServlet that handles HTTP requests and responses, with configurable handler mappings, view resolution, locale, time zone and theme resolution as well as support for uploading files.
· The default handler is based on the @Controller and @RequestMapping annotations, offering a wide range of flexible handling methods.
1) Model : It is normally an application data containing POJO classes, i.e. Plain old Java Object Classes.
2) View : It is responsible for showing the result. This element generates the HTML output which can be displayed on client’s machine.
3) Controller : This element is responsible for processing user requests.


Working
1. The DispatcherServlet receives the HTTP request
2. The DispatcherServlet consults HandlerMapping to call appropriate Controller.
3. The Controller takes the request and finds the appropriate service, sends GET/POST method for calling that service. This service on execution defines the business logic and returns the view name to DispatcherServlet.
4. Using ViewResolver, the DispatcherServlet will choose the appropriate View.
5. This View will then be returned to DispatchServlet to be displayed on the client’s browser window.


Benefits of MVC Framework
Follwing are some features of having MVC framework

1. It provides clear separation of roles such as – controller, validator, model object, handler mapping, view resolver, view and so on.
2. It provides powerful and straightforward configuration of both framework and application classes as Java Beans.
3. It allows re-usability of business code.
4. It also supports for customization, and application level validation.
5. It supports for simple yet powerful tag library.
6. It supports easy integration with any type of view

What is dependency injection ?

1) The dependency injection is a technique whereby one object supplies the dependencies of another object. A dependency is an object that can be used.
2) Dependency Injection is useful when it is required to pass the service to the client rather than allowing a client to build or find the service.
3) Dependency injection allows a client the flexibility of being configurable.
4) The Dependency Injection is a design pattern that removes the dependency of the programs. In such case we provide the information from the external source such as XML file. It makes our code loosely coupled and easier for testing. In such case we write the code as:
class Person {
Phone phone;
Person(Phone phone){
this.phone=phone;
}
public void setPhone(Phone phone){
this.phone=phone;
}
}
In such case, instance of Phone class is provided by external source such as XML file either by constructor or setter method.

What is IoC container ?

  • The core of spring framework is its Inversion of Control (IoC) container.
  • The task of IoC container is to manage the Java objects from instantiation to destruction. These objects are basically called as Spring Beans. A Spring bean in the IoC container can typically be any POJO (plain old java object).
  • The container gets its instructions about which are those objects to instantiate, configure and assemble by reading configuration metadata provided. The configuration metadata can be represented either by XML, Java annotations or Java code.
  • The application POJO classes and configuration metadata are combined to have a fully configured and executable system or application ready for work.

Briefly explain spring bean life cycle.

● During the Bean Life cycle there are two important phases instantiation phase in which the initialization of bean is done and destruction
or removal of bean in which cleanup is done.
 We declare bean using <bean> along with the init-method and
destroy-method parameters.
 These methods can be defined as
public class BeanProgram {


public void init() {
// do some initialization work
}
public void destroy() {
// do some cleanup work
}

}