Spring Interview Questions with Answers

I have tried to collect some top spring core interview questions which you face into your next technical interview. For other spring modules, I will share interview questions and answers separately. I will really appreciate if you can suggest more similar interview questions which you have faced in your previous interviews and you consider them best spring interview questions to be asked. I will add them in this list. This will be great help for fellow learners as well.

1. What is Spring?

Spring is a lightweight system. It can be considered as a system of structures in light of the fact that it gives backing to different structures, for example, Struts, Hibernate, Tapestry, EJB, JSF and so forth.

2. What are benefits of Spring Framework?

Lightweight: Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.

Inversion of control (IOC): Loose coupling is achieved in Spring, with the Inversion of Control technique. The objects give their dependencies instead of creating or looking for dependent objects.

Aspect oriented (AOP): Spring supports Aspect oriented programming and separates application business logic from system services.

Container: Spring contains and manages the life cycle and configuration of application objects.

MVC Framework: Spring's web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks.

Transaction Management: Spring provides a consistent transaction management interface that can scale down to a local transaction and scale up to global transactions (JTA).

Exception Handling: Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO) into consistent, unchecked exceptions.

3. What are the modules of spring framework?

The basic modules of the Spring framework are :

  • Core module
  • Bean module
  • Context module
  • Expression Language module
  • JDBC module
  • ORM module
  • OXM module
  • Java Messaging Service(JMS) module
  • Transaction module
  • Web module
  • Web-Servlet module
  • Web-Struts module
  • Web-Portlet module

4. What is Core Container (Application context) module ?

This is the basic Spring module, which provides the fundamental functionality of the Spring framework. BeanFactory is the heart of any spring-based application. Spring framework was built on the top of this module, which makes the Spring container.

5. What is JoinPoint?

JoinPoint is any point in your program such as field access, method execution, exception handling etc.

6. Does spring framework support all JoinPoints?

No, spring framework supports method execution joinpoint only.

7. What is Advice?

Advice represents action taken by aspect.

8. What are the types of advice in AOP?

There are 5 types of advices in spring AOP.

  1. Before Advice
  2. After Advice
  3. After Returning Advice
  4. Throws Advice
  5. Around Advice

9. What is Pointcut?

Pointcut is expression language of Spring AOP.

10. What is Aspect?

Aspect is a class in spring AOP that contains advices and joinpoints.

11. What is Introduction?

Introduction represents introduction of new fields and methods for a type.

12. What is target object?

Target Object is a proxy object that is advised by one or more aspects.

13. What is interceptor?

Interceptor is a class like aspect that contains one advice only.

14. What is weaving?

Weaving is a process of linking aspect with other application.

15. Does spring perform weaving at compile time?

No, spring framework performs weaving at runtime.

16. What are the AOP implementation?

There are 3 AOP implementation.

  1. Spring AOP
  2. Apache AspectJ
  3. JBoss AOP

17. What does @Controller annotation?

The @Controller annotation marks the class as controller class. It is applied on the class.

18. What does @RequestMapping annotation?

The @RequestMapping annotation maps the request with the method. It is applied on the method.

19. What does the ViewResolver class?

The View Resolver class resolves the view component to be invoked for the request. It defines prefix and suffix properties to resolve the view component.

20. Which ViewResolver class is widely used?

The org.springframework.web.servlet.view.InternalResourceViewResolver class is widely used.

21. Does spring MVC provide validation support?


22. What is Dependency Injection in Spring?

Dependency Injection, an aspect of Inversion of Control (IoC), is a general concept, and it can be expressed in many different ways.This concept says that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (the IOC container) is then responsible for hooking it all up.