Top 80 Spring Interview Questions You Must Prepare In 2025

Last updated on Nov 22,2024 610.4K Views
Sr Research Analyst at Edureka. A techno freak who likes to explore... Sr Research Analyst at Edureka. A techno freak who likes to explore different technologies. Likes to follow the technology trends in market and write...

Top 80 Spring Interview Questions You Must Prepare In 2025

edureka.co

Are you thinking of pursuing your career in Spring Framework? Are you searching for an appropriate QnA set to prepare for your interviews? Here is a blog on Spring Interview Questions which discusses on top 80 questions with proper explanation and examples. It will definitely help you to ace the interviews. But before starting with the Spring Interview Questions, let’s take a quick look on Spring Framework’s demand and status in the market.

Since it’s release, the Spring Framework has continued to bloom in the market. Spring community is continuously coming up with new things and have spread into a vast ecosystem. Today, it holds the top position in the framework market. Check out the below graph which shows the frameworks most frequently used in the market as on January 2018.

Want to Upskill yourself to get ahead in Career? Check out the Top Trending Technologies Article.

You might ask why is Spring certification so much in demand? Well, the answer is, because it provides a comprehensive programming and configuration model for modern Java-based enterprise applications. It is not concerned with the deployment platform used. A key element of Spring Framework is infrastructural support at the application level. It’s very much unlikely to go out of the market in the near future with more major releases announced.

Before we move any further let us take a look some of the most frequently asked Spring Interview Questions,

Q1. What are the major features in different versions of Spring Framework?
Q2. What is a Spring Framework?
Q3. List the advantages of Spring Framework
Q4. What are the different features of Spring Framework?
Q5. How many modules are there in Spring Framework and what are they?
Q6. What is a Spring configuration file?
Q7. What are the different components of a Spring application?
Q8. What are the various ways of using Spring Framework?
Q9. What is Spring IOC Container?
Q10. What do you mean by Dependency Injection?

So, here are the Top 80 Spring Interview Questions which are most likely to be asked by the interviewer. If you are seeking a future in this field, these questions will surely help you to ace the interview. For your ease of access, I have categorized the questions under a few topics, namely:

You may watch the webinar recording of Spring Interview Questions where our instructor has shared his experience and expertise that will help you to crack any Spring Interview.

Spring Interview Questions and Answers for 2025 | Edureka

 

Let’s begin with the first section of Spring interview questions, which is the General Questions.

General Spring Interview Questions

1. What are the major features in different versions of Spring Framework?

Features of Spring Framework

VersionLogoFeature
Spring 2.5This version was released in 2007. It was the first version which supported annotations.
Spring 3.0This version was released in 2009. It made full-fledged use of improvements in Java5 and also provided support to JEE6.
Spring 4.0 This version was released in 2013. This was the first version to provide full support to Java 8.

2. What is a Spring Framework?

3. List the advantages of Spring Framework.

4. What are the different features of Spring Framework?

Following are some of the major features of Spring Framework :

5. How many modules are there in Spring Framework and what are they?

There are around 20 modules which are generalized into Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation and Test.

  1. Spring Core
  2. Spring Bean
  3. SpEL (Spring Expression Language)
  4. Spring Context 
  1. JDBC (Java DataBase Connectivity)
  2. ORM (Object Relational Mapping)
  3. OXM (Object XML Mappers)
  4. JMS (Java Messaging Service)
  5. Transaction
  1. Web
  2. Web – MVC
  3. Web – Socket
  4. Web – Portlet

Few Miscellaneous modules are given below:

6. What is a Spring configuration file?

A Spring configuration file is an XML file. This file mainly contains the classes information. It describes how those classes are configured as well as introduced to each other. The XML configuration files, however, are verbose and more clean. If it’s not planned and written correctly, it becomes very difficult to manage in big projects.

7. What are the different components of a Spring application?

A Spring application, generally consists of following components:

8. What are the various ways of using Spring Framework?

Spring Framework can be used in various ways. They are listed as follows:

  1.  As a Full-fledged Spring web application.
  2. As a third-party web framework, using Spring Frameworks middle-tier.
  3.  For remote usage. 
  4. As Enterprise Java Bean which can wrap existing POJOs (Plain Old Java Objects).

 

Spring Dependency Injection/ IoC Container Interview Questions

9. What is Spring IOC Container?

At the core of the Spring Framework, lies the Spring container. The container creates the object, wires them together, configures them and manages their complete life cycle. The Spring container makes use of Dependency Injection to manage the components that make up an application. The container receives instructions for which objects to instantiate, configure, and assemble by reading the configuration metadata provided. This metadata can be provided either by XML, Java annotations or Java code.

10. What do you mean by Dependency Injection? 

In Dependency Injection, you do not have to create your objects but have to describe how they should be created. You don’t connect your components and services together in the code directly, but describe which services are needed by which components in the configuration file. The IoC container will wire them up together.

11. In how many ways can Dependency Injection be done?

In general, dependency injection can be done in three ways, namely :

In Spring Framework, only constructor and setter injections are used.

12. Differentiate between constructor injection and setter injection.

Constructor Injection vs Setter Injection

Constructor InjectionSetter Injection
There is no partial injection.There can be partial injection.
It doesn’t override the setter property.It overrides the constructor property.
It will create a new instance if any modification is done.It will not create new instance if any modification is done.
It works better for many properties.It works better for few properties.

13. How many types of IOC containers are there in spring?

  1. BeanFactory: BeanFactory is like a factory class that contains a collection of beans. It instantiates the bean whenever asked for by clients.
  2. ApplicationContext: The ApplicationContext interface is built on top of the BeanFactory interface. It provides some extra functionality on top BeanFactory.

14. Differentiate between BeanFactory and ApplicationContext.

BeanFactory vs ApplicationContext

BeanFactoryApplicationContext
It is an interface defined in org.springframework.beans.factory.BeanFactoryIt is an interface defined in org.springframework.context.ApplicationContext
It uses Lazy initializationIt uses Eager/ Aggressive initialization
It explicitly provides a resource object using the syntaxIt creates and manages resource objects on its own
It doesn’t supports internationalizationIt supports internationalization 
It doesn’t supports annotation based dependency    It supports annotation based dependency  

15.  List some of the benefits of IoC.

Some of the benefits of IoC are:

16. In which scenario, you will use singleton and prototype scope?

Use Singleton Scope when you want to have only one instance shared across the entire application.

Use Prototype Scope when you want a new instance created every time it’s requested, providing independence for each part of the application.

17. What is the @Controller annotation used for?

The @Controller annotation is used in the Spring Framework for Java to mark a class as a controller component. It is part of the Spring MVC (Model-View-Controller) architecture, which is used to build web applications in a structured and organized way.

When you annotate a class with @Controller, Spring recognizes it as a controller and allows it to handle HTTP requests and generate HTTP responses. Controllers are responsible for processing user requests, interacting with the application’s business logic (services), and returning the appropriate view to render the response.

18. Can you create a controller without using @Controller or @RestController annotations?

Yes, you can create a controller in Spring without using the @Controller or @RestController annotations. The @Controller and @RestController annotations are just convenience annotations that provide specific functionalities, but you can achieve the same functionality by using other annotations or configuration.

To create a controller without using @Controller or @RestController, you can use the following approach:

19. What is ContextLoaderListener and what does it do?

The ContextLoaderListener is a Spring Framework component used in Java web applications to load the Spring application context when the web application starts. It initializes the IoC container, manages beans, and allows components to access Spring beans for their processing.

 

20. What are the differences between @RequestParam and @PathVariable annotations?

@requestParam@pathVariable
PurposeExtracts query parameters from the URL’s query string.Extracts values from the URI path itself (URL template).
SyntaxFollowed by the parameter name in the controller method’s parameter list.Followed by the variable name in curly braces {} within the URL mapping.
ExampleURL/example?name=John/example/{id}
Example Usage@RequestParam(“name”) String name@PathVariable(“id”) String id
Use CaseSuitable for optional parameters or data in the query string.Useful for extracting dynamic values from the URL path.

21. What is the use of @Autowired annotation?

The @Autowired annotation in Spring is used to automatically wire (inject) dependencies into a Spring bean. It enables automatic dependency injection, meaning that Spring will automatically find and inject the required dependencies into the bean without the need for manual configuration.

22. What is the role of @ModelAttribute annotation?

The @ModelAttribute annotation in Spring MVC is used to bind method parameters or method return values to model attributes. It plays a crucial role in the Model-View-Controller (MVC) architecture, where it helps transfer data between the Controller and the View.

The key role of @ModelAttribute is to facilitate data transfer between the Controller and the View. It allows you to pre-populate form data when displaying forms to users and automatically bind user inputs to model attributes when processing form submissions. Additionally, it helps in adding common attributes (like reference data) to the model across multiple controller methods.

23. 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, and listeners, as well as handling error pages. While newer Spring applications rely more on annotation-based configuration, web.xml remains essential for certain settings and legacy support.

 

24. What are the types of Spring MVC Dependency Injection?

The three types of Dependency Injection in Spring MVC are:

25. What is the importance of session scope?

The session scope in Spring is an important mechanism for managing beans in web applications. It allows you to create and maintain a separate instance of a bean for each user session, ensuring that data associated with a specific user is preserved throughout their interactions with the application.

26. What is the importance of @Required annotation?

The @Required annotation was used in earlier versions of Spring to indicate that a property of a bean must be set (or wired) with a value before the bean can be fully initialized. However, starting from Spring 3.0, the @Required annotation has been deprecated and is no longer recommended for use.

 

27. Differentiate between the @Autowired and the @Inject annotations.

 

@autowired@inject
FrameworkPart of the Spring FrameworkPart of the JSR-330 standard (Java Dependency Injection)
ConfigurationRequires enabling component scanning in SpringRequires a JSR-330 compliant DI framework
QualificationSupports qualifiers like @Qualifier and @PrimaryDoes not have built-in qualifier support
Optional DependencyBy default, the dependency is requiredBy default, the dependency is not required
Optional ConfigurationCan use @Autowired(required = false)Can use @Inject without changing its default behavior

28. Are singleton beans thread-safe?

Yes, singleton beans in Spring are thread-safe by default. When you define a bean with singleton scope in Spring, the container ensures that only one instance of that bean is created and shared across all requests within the container’s context.

29. How can you achieve thread-safety in beans?

Yes, singleton beans in Spring are thread-safe by default. When you define a bean with singleton scope in Spring, the container ensures that only one instance of that bean is created and shared across all requests within the container’s context.

singleton beans in Spring are thread-safe as long as they are stateless or properly synchronized when dealing with mutable state. The Spring container manages singleton bean instantiation and synchronization to ensure their thread safety within the context.

 

30. What is the significance of @Repository annotation?

The @Repository annotation in Spring is a specialized stereotype annotation that serves as a marker for classes that fulfill the role of a data repository or DAO (Data Access Object). It is primarily used to indicate that the class is responsible for data access operations, such as reading from and writing to a database or any other external data source

31. How is the dispatcher servlet instantiated?

 The DispatcherServlet is automatically instantiated and initialized by the Servlet container during web application startup. It acts as the front controller for Spring MVC applications, managing the entire request-response lifecycle and delegating the processing to the appropriate components in the Spring application context.

32. How is the root application context in Spring MVC loaded?

The root application context in Spring MVC is loaded automatically during web application startup by the ContextLoaderListener. It handles overall configuration and bean management for the application, while the DispatcherServlet handles web-specific components and request handling.

 

33. How does the Spring MVC flow look like? In other words, How does a DispatcherServlet know what Controller needs to be called when there is an incoming request to the Spring MVC?

 

The Spring MVC flow involves several components working together to handle incoming requests and route them to the appropriate controllers for processing.

The DispatcherServlet plays a central role in the Spring MVC flow. It receives incoming requests, selects the appropriate controller based on the URL mapping, invokes the controller method to handle the request, prepares the model data and view, resolves the view, and finally sends the response back to the client. The flow is orchestrated through a combination of handler mappings, controllers, view resolvers, and views, allowing Spring MVC to handle various types of requests and produce dynamic responses.

 

34. Where does the access to the model from the view come from?

In Spring MVC, the Model object acts as a container to pass data from the Controller to the View for rendering. The Model is automatically made available to the View by the DispatcherServlet, and the View can access the data using expression language or template-specific syntax. This allows for separation of data handling and presentation concerns in the application.

35. Why do we need BindingResults?

BindingResult is used in Spring MVC for data binding and validation. It captures errors during form submission, helps prevent exceptions, and allows you to handle errors gracefully by displaying error messages to the user.

36. What are Spring Interceptors?

Spring Interceptors are components in the Spring MVC framework that allow you to intercept and process HTTP requests and responses. They provide a way to perform pre-processing and post-processing tasks before and after the actual request is handled by a controller or after the response is generated.

37. Is there any need to keepspring-mvc.jar on the classpath or is it already present as part of Spring-core

The spring-mvc.jar file is not part of the spring-core library, and they serve different purposes.

So, if you’re building an application using the Spring MVC framework, you would need both spring-core and spring-webmvc on your classpath. These libraries are usually managed by a build tool like Maven or Gradle, and are automatically included when you specify them as dependencies in your build file.

38. What is the Model in Spring MVC?

In the context of Spring MVC, the term “Model” represents the data layer. It is a map (similar to a java.util.Map) that contains data to be rendered by the View. This data is typically the outcome of executing your business logic, which you want to show to the user.

39. What are the differences between the <context:annotation-config> vs <context:component-scan> tags?

 

<context:annotation-config>: This is used to activate various annotations within Spring-managed beans. For example, if you have beans that are manually defined in your XML file and these beans have annotations like @Autowired, @PostConstruct, @PreDestroy, @Resource, etc., you need <context:annotation-config> to activate these annotations. However, it does not automatically detect and instantiate beans from the classpath.

 

<context:component-scan>: This tag does everything that <context:annotation-config> does, but it goes one step further. It scans the classpath for classes annotated with @Component, @Service, @Repository, @Controller, etc., and automatically registers them as beans in the Spring application context. In other words, it automatically detects and instantiates your beans. So, when you use <context:component-scan>, you don’t need to explicitly define each bean in your XML configuration file, as long as they are annotated correctly and exist within the base-package specified by <context:component-scan>.

40. How is the form data validation done in Spring Web MVC Framework?

Form data validation in Spring Web MVC Framework is done by:

 

 

 

 

 

41. How to get ServletConfig and ServletContext objects in spring bean?

 

In a Spring application, you can access ServletConfig and ServletContext objects by implementing the ServletContextAware and ServletConfigAware interfaces. These interfaces provide setter methods that Spring will use to inject the necessary objects.

42. Differentiate between a Bean Factory and an Application Context.

BeanFactory

ApplicationContext

43. How are i18n and localization supported in Spring MVC?

Internationalization (i18n) and localization (L10n) are important features for applications that need to support multiple languages or locales. In Spring MVC, these are supported using a combination of LocaleResolver, LocaleChangeInterceptor, and message source properties files.

 

44. What do you understand by MultipartResolver?

MultipartResolver is an interface defined in Spring MVC framework that is used for uploading files. When a form in a Spring web application is submitted and it has enctype=”multipart/form-data”, the MultipartResolver implementation handles the file upload part of the request.

The MultipartResolver is part of the Spring DispatcherServlet’s configuration, so you’ll define it in your Spring configuration. 

 

45. How is it possible to use the Tomcat JNDI DataSource in the Spring applications?

 

To use a Tomcat JNDI DataSource in a Spring application:

 

 

 

 

Spring Beans Interview Questions

46. Explain Spring Beans?

47. How configuration metadata is provided to the Spring container?

Configuration metadata can be provided to Spring container in following ways:

<bean id="studentbean" class="org.edureka.firstSpring.StudentBean">
 <property name="name" value="Edureka"></property>
</bean>
<beans>
<context:annotation-config/>
<!-- bean definitions go here -->
</beans>
1. @Bean annotation plays the same role as the <bean/> element. 

2.@Configuration classes allows to define inter-bean dependencies by simply calling other @Bean methods in the same class.

For example:
@Configuration 
public class StudentConfig 
{ 
@Bean
public StudentBean myStudent() 
{ return new StudentBean(); }
}

48. How many bean scopes are supported by Spring?

The Spring Framework supports five scopes. They are:

The last three are available only if the users use a web-aware ApplicationContext.

49. What is the Bean life cycle in Spring Bean Factory Container?

Bean life cycle in Spring Bean Factory Container is as follows:

  1. The Spring container instantiates the bean from the bean’s definition in the XML file.
  2. Spring populates all of the properties using the dependency injection, as specified in the bean definition.
  3. The factory calls setBeanName() by passing the bean’s ID, if the bean implements the BeanNameAware interface.
  4. The factory calls setBeanFactory() by passing an instance of itself, if the bean implements the BeanFactoryAware interface.
  5. preProcessBeforeInitialization() methods are called if there are any BeanPostProcessors associated with the bean.
  6. If an init-method is specified for the bean, then it will be called.
  7. Finally, postProcessAfterInitialization() methods will be called if there are any BeanPostProcessors associated with the bean.

To understand it in better way check the below diagram:

50. Explain inner beans in Spring.

A bean can be declared as an inner bean only when it is used as a property of another bean. For defining a bean, the Spring’s XML based configuration metadata provides the use of <bean> element inside the <property> or <constructor-arg>. Inner beans are always anonymous and they are always scoped as prototypes. For example, let’s say we have one Student class having reference of Person class. Here we will be creating only one instance of Person class and use it inside Student.

Here’s a Student class followed by bean configuration file:

Student.java

public class Student
{
private Person person;
//Setters and Getters
}
public class Person
{
private String name;
private String address;
//Setters and Getters
}

studentbean.xml

<bean id=&ldquo;StudentBean" class="com.edureka.Student">
<property name="person">
<!--This is inner bean -->
<bean class="com.edureka.Person">
<property name="name" value=&ldquo;Scott"></property>
<property name="address" value=&ldquo;Bangalore"></property>
</bean>
</property>
</bean>

51. Define Bean Wiring.

When beans are combined together within the Spring container, it’s called wiring or bean wiring. The Spring container needs to know what beans are needed and how the container should use dependency injection to tie the beans together, while wiring beans.

52. What do you understand by auto wiring and name the different modes of it?

The Spring container is able to autowire relationships between the collaborating beans. That is, it is possible to let Spring resolve collaborators for your bean automatically by inspecting the contents of the BeanFactory.
Different modes of bean auto-wiring are:

  1. no: This is default setting which means no autowiring. Explicit bean reference should be used for wiring.
  2. byName: It injects the object dependency according to name of the bean. It matches and wires its properties with the beans defined by the same names in the XML file.
  3. byType: It injects the object dependency according to type. It matches and wires a property if its type matches with exactly one of the beans name in XML file.
  4. constructor: It injects the dependency by calling the constructor of the class. It has a large number of parameters.
  5. autodetect: First the container tries to wire using autowire by constructor, if it can’t then it tries to autowire by byType.

53. What are the limitations with auto wiring?

Following are some of the limitations you might face with auto wiring:

 

Spring Annotations Interview Questions

54. What do you mean by  Annotation-based container configuration?

Instead of using XML to describe a bean wiring, the developer moves the configuration into the component class itself by using annotations on the relevant class, method, or field declaration. It acts as an alternative to XML setups. For example:

@Configuration 
public class AnnotationConfig
{
@Bean 
public MyDemo myDemo()
 { return new MyDemoImpll(); }
}

55. How annotation wiring can be turned on in Spring?

By default, Annotation wiring is not turned on in the Spring container. Thus, to use annotation based wiring we must enable it in our Spring configuration file by configuring <context:annotation-config/> element. For example:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context">
<context:annotation-config/>
<beans &hellip;&hellip;&hellip;&hellip; />
</beans>

56. What’s the difference between @Component, @Controller, @Repository & @Service annotations in Spring?

@Component: This marks a java class as a bean. It is a generic stereotype for any Spring-managed component. The component-scanning mechanism of spring now can pick it up and pull it into the application context.

@Controller: This marks a class as a Spring Web MVC controller. Beans marked with it are automatically imported into the Dependency Injection container.

@Service: This annotation is a specialization of the component annotation. It doesn’t provide any additional behavior over the @Component annotation. You can use @Service over @Component in service-layer classes as it specifies intent in a better way.

@Repository: This annotation is a specialization of the @Component annotation with similar use and functionality. It provides additional benefits specifically for DAOs. It imports the DAOs into the DI container and makes the unchecked exceptions eligible for translation into Spring DataAccessException.

57. What do you understand by @Required annotation?

@Required is applied to bean property setter methods. This annotation simply indicates that the affected bean property must be populated at the configuration time with the help of an explicit property value in a bean definition or with autowiring. If the affected bean property has not been populated, the container will throw BeanInitializationException.

For example:

public class Employee
{
private String name;
@Required
public void setName(String name)
{this.name=name; }
public string getName()
{ return name; }
}

58. What do you understand by @Autowired annotation?

The @Autowired annotation provides more accurate control over where and how autowiring should be done. This annotation is used to autowire bean on the setter methods, constructor, a property or methods with arbitrary names or multiple arguments. By default, it is a type driven injection.

For Example:

public class Employee
{
private String name;
@Autowired
public void setName(String name)
{this.name=name; }
public string getName()
{ return name; }
}

59. What do you understand by @Qualifier annotation?

When you create more than one bean of the same type and want to wire only one of them with a property  you can use the @Qualifier annotation along with @Autowired to remove the ambiguity by specifying which exact bean should be wired.

For example, here we have two classes, Employee and EmpAccount respectively. In EmpAccount, using @Qualifier its specified that bean with id emp1 must be wired.

Employee.java

public class Employee
{
private String name;
@Autowired
public void setName(String name)
{ this.name=name; }
public string getName()
{ return name; }
}

EmpAccount.java

public class EmpAccount
{
private Employee emp;
@Autowired
@Qualifier(emp1)
public void showName()
{
System.out.println(&ldquo;Employee name : &rdquo;+emp.getName);
}
}

60.  What do you understand by @RequestMapping annotation?

@RequestMapping annotation is used for mapping a particular HTTP request method to a specific class/ method in controller that will be handling the respective request. This annotation can be applied at both levels:

 

Spring Data Access Interview Questions

61. Describe Spring DAO support?

The Data Access Object (DAO) support in Spring makes it easy to work with data access technologies like JDBC, Hibernate or JDO in a consistent way. This allows one to switch between the persistence technologies easily. It also allows you to code without worrying about catching exceptions that are specific to each of these technology.

62. Name the exceptions thrown by the Spring DAO classes.

See the below diagram, it depicts all the Spring DAO classes in the hierarchical order.

63.  Which classes are present in spring JDBC API?

Classes present in JDBC API are as follows:

  1. JdbcTemplate
  2. SimpleJdbcTemplate
  3. NamedParameterJdbcTemplate
  4. SimpleJdbcInsert
  5. SimpleJdbcCall

64. What are the ways by which Hibernate can be accessed using Spring?

There are twways by which we can access Hibernate using Spring:

  1. Inversion of Control with a Hibernate Template and Callback
  2. Extending HibernateDAOSupport and Applying an AOP Interceptor node

65. Name the types of transaction management that Spring supports.

Two types of transaction management are supported by Spring. They are:

  1. Programmatic transaction management: In this, the transaction is managed with the help of programming. It provides you extreme flexibility, but it is very difficult to maintain.
  2. Declarative transaction management: In this, the transaction management is separated from the business code. Only annotations or XML based configurations are used to manage the transactions.

66. What are the different ORM’s supported by Spring?

Different ORM’s supported by Spring are depicted via the below diagram:


Spring AOP Interview Questions

67. Describe AOP.

Aspect-oriented programming or AOP is a programming technique which allows programmers to modularize crosscutting concerns or behavior that cuts across the typical divisions of responsibility. Examples of cross-cutting concerns can be logging and transaction management. The core of AOP is an aspect. It encapsulates behaviors that can affect multiple classes into reusable modules.

68. What do you mean by Aspect?

Aspect is a modularization of concern which cuts across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. Aspects are implemented using regular classes or regular classes annotated with the @Aspect annotation in Spring Framework.

69. Explain JoinPoint.

A point during the execution of a program is called JoinPoint, such as the execution of a method or the handling of an exception. In Spring AOP, a joinpoint always represents a method execution.

70. What is an Advice?

An Action taken by an aspect at a particular joinpoint is known as an Advice. Spring AOP uses an advice as an interceptor, maintaining a chain of interceptors “around” the join point.

71. What are the different types of Advices?

Different types of Advices in Spring AOP are:

  1. Before: These types of advices execute before the joinpoint methods and are configured using @Before annotation mark.
  2. After returning: These types of advices execute after the joinpoint methods completes executing normally and are configured using @AfterReturning annotation mark.
  3. After throwing:  These types of advices execute only if joinpoint method exits by throwing an exception and are configured using @AfterThrowing annotation mark.
  4. After (finally): These types of advices execute after a joinpoint method, regardless of the method’s exit whether normally or exceptional return and are configured using @After annotation mark.
  5. Around: These types of advices execute before and after a joinpoint and are configured using @Around annotation mark.

72. Point out the difference between concern and cross-cutting concern in Spring AOP?

The concern is the behavior we want to have in a particular module of an application. It can be defined as a functionality we want to implement. 

The cross-cutting concern is a concern which is applicable throughout the application. This affects the entire application. For example, logging, security and data transfer are the concerns needed in almost every module of an application, thus they are the cross-cutting concerns.

73. What are the different AOP implementations?

Different AOP implementations are depicted by the below diagram:

74. What are the difference between Spring AOP and AspectJ AOP?

Spring AOP vs AspectJ AOP

Spring AOPAspectJ AOP
Runtime weaving through proxy is doneCompile time weaving through AspectJ Java tools is done 
It supports only method level PointCutIt suports field level Pointcuts
It is DTD based It is schema based and Annotation configuration

75. What do you mean by Proxy in Spring Framework?

An object which is created after applying advice to a target object is known as a Proxy. In case of client objects the target object and the proxy object are the same.

76. In Spring, what is Weaving?

The process of linking an aspect with other application types or objects to create an advised object is called Weaving. In Spring AOP, weaving is performed at runtime. Refer the below diagram:

The last section of Spring interview questions is on Spring MVC Interview Questions.

Spring MVC Interview Questions

77. What do you mean by Spring MVC framework?

The Spring web MVC framework provides model-view-controller architecture and ready to use components that are used to develop flexible and loosely coupled web applications. The MVC pattern helps in separating the different aspects of the application like input logic, business logic and UI logic, while providing a loose coupling between all these elements. Get Started with Spring MVC

78. Describe DispatcherServlet.

The DispatcherServlet is the core of Spring Web MVC framework. It handles all the HTTP requests and responses. The DispatcherServlet receives the entry of handler mapping from the configuration file and forwards the request to the controller. The controller then returns an object of Model And View. The DispatcherServlet checks the entry of view resolver in the configuration file and calls the specified view component.

79. Explain WebApplicationContext.

The WebApplicationContext is an extension of the plain ApplicationContext. It has some extra features that are necessary for web applications. It differs from a normal ApplicationContext in terms of its capability of resolving themes and in deciding which servlet it is associated with.

80. In Spring MVC framework, what is controller?

Controllers provide access to the application behavior. These behaviors are generally defined through a service interface. Controllers interpret the user input and transform it into a model which is represented to the user by the view. In Spring, controller is implemented in a very abstract way. It also enables you to create a wide variety of controllers.

  

I hope this set of Spring Interview Questions and Answers will help you in preparing for your interviews. All the best!

If you want to learn Spring and wish to use it while developing Java applications, then check out the Spring Certification Training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.

 

Got a question for us? Please mention it in the comments section and we will get back to you.

 

 

BROWSE COURSES
REGISTER FOR FREE WEBINAR A Comprehensive UI/UX Design Tutorial