Spring MVC


Spring Boot


1) What is Spring Boot?

Spring Boot is a Spring module which provides RAD (Rapid Application Development) feature to Spring framework.

It is used to create stand alone spring based application that you can "just run" because it needs very little spring configuration.

2) Explain the difference between Spring Boot, Spring MVC and Spring.

One of the most important features of the Spring framework is that it is Dependency Injection (or IOC). 
The core of all Spring Modules is IOC (Inversion of Control) or Dependency Injection. 
When Dependency Injection (or IOC) is used by the engineer appropriately, users can develop loosely-coupled applications which can easily be tested.

The Spring MVC Framework provides a couple of ways to develop web applications such as by using concepts such as Dispatcher Servlet, ModelAndView and View Resolver.

The main problem about the Spring Framework and the Spring MVC framework is the amount of configuration that is required to get it setup. 
Spring Boot has auto configuration as well as other non-functional features that make it easier to build production-ready applications.


Spring MVC

1) What is MVC?

The MVC (Model-View-Controller) is a software architectural design pattern. 
It separates the functionality of an application into three interconnected parts - Model, View, and Controller. 
This approach facilitates the reusability of the code and parallel development.

2) What is Spring MVC?

A Spring MVC is a Java Framework which is used to develop dynamic web applications.
It implements all the basic features of a core spring framework like Inversion of Control and Dependency Injection. It follows the Model-View-Controller design pattern.

Model - A model contains the data of the application. Data can be a single object or a collection of objects.
Controller - A controller contains the business logic of an application. Here, the @Controller annotation is used to mark the class as the controller.
View - A view represents the provided information in a particular format. So, we can create a view page by using view technologies like JSP+JSTL, Apache Velocity, Thymeleaf, and FreeMarker.

3) What is the front controller of Spring MVC?

The front controller is a DispatcherServlet class present in org.springframework.web.servlet package.
 It dispatches the request to the appropriate controller and manages the flow of the application. 
It is required to specify the DispatcherServlet class in the web.xml file.

4) Explain the flow of Spring MVC?

Once the request has been generated, it intercepted by the DispatcherServlet that works as the front controller.
The DispatcherServlet gets an entry of handler mapping from the XML file and forwards the request to the controller.
The controller returns an object of ModelAndView.
The DispatcherServlet checks the entry of view resolver in the XML file and invokes the specified view component.

6) What does an additional configuration file contain in Spring MVC application?

The Spring MVC application contains an additional configuration file that contains the properties information. 
This file can be created either in the form of an xml file or properties file.
In this file, we generally define the base-package and view resolver where DispatcherServlet searches for the controller classes and view components path. 
However, it can also contain various other configuration properties.

7) What is an InternalResourceViewResolver in Spring MVC?

The InternalResourceViewResolver is a class which is used to resolve internal view in Spring MVC. 
Here, you can define the properties like prefix and suffix where prefix contains the location of view page and suffix contains the extension of view page.

 For example:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/WEB-INF/jsp/"></property>  
        <property name="suffix" value=".jsp"></property>          
     </bean>

8) Name the annotations used to handle different types of incoming HTTP request methods?

The following annotations are used to handle different types of incoming HTTP request methods: 

@GetMapping
@PostMapping
@PutMapping
@PatchMapping
@DeleteMapping

9) What are some of the important Spring annotations you have used?

Some of the Spring annotations that I have used in my project are:

@Controller – for controller classes in Spring MVC project.
@RequestMapping – for configuring URI mapping in controller handler methods. 
@ResponseBody – for sending Object as response, usually for sending XML or JSON data as response.
@PathVariable – for mapping dynamic values from the URI to handler method arguments.
@Autowired – for autowiring dependencies in spring beans.
@Qualifier – with @Autowired annotation to avoid confusion when multiple instances of bean type is present.
@Service – for service classes.
@Scope – for configuring scope of the spring bean.
@Configuration, @ComponentScan and @Bean – for java based configurations.
AspectJ annotations for configuring aspects and advices, @Aspect, @Before, @After, @Around, @Pointcut etc.