Index.
jsp
/hello
Display(){ return “viewpage”;}
Spring core Interview questions
1. What is the Spring Framework?
a. Explain its core features and why it is used in Java
development.
.
2. What is Dependency Injection (DI)?
a. Define DI and its types (constructor-based, setter-
based).
3. What is the difference between BeanFactory and
ApplicationContext?
a. Explain lazy initialization and advanced features of
ApplicationContext.
4. How do you define a bean in Spring?
a. XML configuration, annotations (@Component,
@Service, @Repository, @Controller), and Java-
based configuration.
5. What is Inversion of Control (IoC)?
a. Explain the IoC principle and its implementation in
Spring.
6. What are annotations in Spring?
a. Discuss annotations like @Component, @Autowired,
@Qualifier, @Primary, etc.
7. What is the difference between @Component,
@Service, @Repository, and @Controller?
a. Discuss their roles and usage.
8. How does Spring Framework achieve loose coupling?
a. Dependency Injection and Interface-based
programming.
9. What is the purpose of the @Configuration and @Bean
annotations?
a. Java-based configuration for defining beans.
10. What is the difference between @RequestMapping
and @GetMapping?
a. Explain specific HTTP method mapping.
Spring MVC Questions
1. What is Spring MVC?
o Spring MVC is a module of the Spring Framework
used to build web applications. It follows the Model-
View-Controller design pattern to separate application
logic, UI, and data handling.
2. What are the main components of Spring MVC?
o DispatcherServlet: Front controller that dispatches
requests.
o Controller: Handles user requests.
o Model: Carries data between controller and view.
o View: Represents the UI (e.g., JSP, Thymeleaf).
3. How does Spring MVC work?
o The DispatcherServlet intercepts requests, maps them
to the appropriate controller using handler mappings,
processes the request, and returns a view.
4. What is DispatcherServlet in Spring MVC?
o It is the front controller in Spring MVC that handles
all incoming HTTP requests and routes them to the
appropriate handler methods.
5. What is @Controller in Spring MVC?
o @Controller is used to define a class as a Spring MVC
controller to handle web requests.
6. What is @RequestMapping?
o It maps HTTP requests to handler methods in a
controller. Example:
@RequestMapping(value = "/home", method =
RequestMethod.GET)
public String home() {
return "home"; // View name
}
7. Difference between @Controller and @RestController?
o @Controller: Used to return views (e.g., JSPs or
HTML).
o @RestController: Combines @Controller and
@ResponseBody to return JSON or XML data
directly.
8.What is the role of ViewResolver in Spring MVC?
o A ViewResolver maps logical view names returned by
controllers to actual view files (e.g., JSP templates).