Spring Interview Questions

What is Spring Framework?

Spring is an integrated framework to develop enterprise applications and to reduce the complexity of enterprise application development. It is a lightweight process and it is loosely coupled. It supports various frameworks such as Struts, Hibernate, Tapestry, EJB, JSF, etc.

What are the features of Spring framework?

What are the modules available in Spring framework?

We have a lot of modules available in the Spring framework like Data access, web, core container, AOP, Test, etc.

Explain IOC?

IOC stands for Inversion of Control. It is used to create, configure, and manage the lifecycle of objects and their dependencies. IOC gets the information of objects from a configuration file (XML) or Java Annotations and Java POJO class.

Explain DI in Spring framework?

Dependency Injection (DI) makes our programming code loosely coupled by removing dependencies from the program, making it easy to manage and test applications.

What is Spring Configuration file?

An XML file is a Spring configuration file, which mainly contains the information of classes and describes how these classes are configured and introduced to each other.

What is the use of IOC container in Spring framework?

IOC gets the information of objects from a configuration file (XML) and performs the following tasks:

How many ways can Dependency Injection be done?

There are three ways Dependency Injection can be done:

What is the difference between BeanFactory and ApplicationContext?

BeanFactory and ApplicationContext both are Java interfaces. BeanFactory is a basic container, whereas ApplicationContext is an advanced container. ApplicationContext extends BeanFactory and supports additional features like integration with Spring AOP. Both use XML files for configuration, but ApplicationContext also supports Java configuration.

What are the different components of a Spring application?

Differentiate between constructor injection and setter injection?

Constructor Injection is used when dependencies are mandatory, and all required properties are passed to the constructor. Setter Injection is used for optional dependencies and allows for partial injection. Setter Injection can override Constructor Injection, allowing for easy changes to property values without creating new bean instances.

What is autowiring in Spring?

Autowiring enables automatic dependency injection by the Spring framework, which can automatically wire relationships between collaborating beans based on configurations in the Spring configuration file.

Explain the AOP module?

The AOP module is used for developing aspects for Spring-enabled applications, providing support for cross-cutting concerns like logging, security, and transaction management.

Explain the web module in Spring framework?

The Spring web module is built on the application context module, providing a context appropriate for web-based applications. It supports tasks like handling multipart requests for file uploads and binding request parameters to business objects, as well as integration with Jakarta Struts.

What are the different types of IoC (dependency injection)?

What is Spring MVC module?

The Spring MVC framework is provided for building web applications, offering a clean separation of controller logic from business objects through IoC. It can be integrated with other MVC frameworks, but Spring MVC is preferred for its use of IoC.

What are Spring beans?

Spring beans are Java objects managed by the Spring IoC container, created with configuration metadata supplied by users, and form the backbone of a Spring application.

What is the importance of the web.xml in Spring MVC?

The web.xml file in Spring MVC is used for configuring the DispatcherServlet, defining context parameters, filters, listeners, and handling error pages. It remains essential for certain settings and legacy support despite newer annotation-based configurations.

What is the importance of session scope?

Session scope allows for creating and maintaining separate bean instances for each user session, ensuring data associated with a specific user is preserved throughout their interactions with the application.

What is bean wiring?

Bean wiring refers to the process of combining beans within the Spring container and specifying how the container should use dependency injection to tie them together.

What are the advantages of Spring AOP?

Spring AOP allows breaking code logic into distinct parts, enabling dynamic addition or removal of concerns before or after business logic, making the code easy to maintain and pluggable.

What is JoinPoint?

A JoinPoint represents any point in the program where an AOP aspect can be plugged in, such as method execution or exception handling.

What are Spring Interceptors?

Spring Interceptors are components that allow intercepting and processing HTTP requests and responses in the Spring MVC framework, performing pre-processing and post-processing tasks around controller handling.

Can you inject null and empty string values in Spring?

Yes, null and empty string values can be injected in Spring.

What is @Autowired annotation?

The @Autowired annotation in Spring is used for automatic dependency injection, allowing Spring to find and inject required dependencies into a bean without manual configuration.

What is @Required annotation?

The @Required annotation indicates that a bean property must be populated at configuration time, either through explicit property value or auto wiring, with the container throwing BeanInitializationException if not populated.

What is @Qualifier annotation?

The @Qualifier annotation is used alongside @Autowired to specify which exact bean should be wired when there are multiple beans of the same type.

What is @RequestMapping annotation?

@RequestMapping is used for mapping HTTP request methods to specific class/method in a controller, handling the respective requests, and can be applied at both class and method levels.

What is DispatcherServlet?

The DispatcherServlet in the Spring Web MVC framework handles all HTTP requests and responses, returning a ModelAndView object and calling the specified view component based on the view resolver configuration.

What are the different types of AutoProxying?

What is a proxy?

A proxy is an object created after applying advice to a target object, with the client object interacting with the proxy as if it were the target object.

What are the differences between Spring AOP and AspectJ AOP?

Explain the concept of Aspect?

An Aspect in Spring AOP is a module encapsulating a concern, defining cross-cutting concerns like transaction management, security, and logging, applied to target objects for modularized implementation.