Spring interview questions

Spring interview questions

Spring is an open source development framework for enterprise Java. The main features of spring may be used for developing applications of Java. Also, extensions for making web applications on top of JavaEE platform can be done. The main goal of spring is to make the development of J2EE development a lot easier to use and promote a programming practice by making use of POJO-based models. Spring is a lightweight framework. It can also be termed as the framework of frameworks because it also provides to other frameworks like EJB, JSF, Tapestry, Hibernate etc. This framework is defined as a structure using which we can find the solutions to various technical problems. It comprises many modules like ORM, DAO, AOP, WEB MVC etc.

Read Best Spring interview questions and their answers

We hereby provide you with some questions on spring. These Spring Interview Questions have been specially designed so that it will help you to understand the nature of questions you may encounter while you are in an interview and the subject is spring.

In many interviews, interviewers start questioning the basic concept and then ask questions based on how you answer the basic ones.

Download Spring interview questions PDF

Spring interview questions

Following are the disadvantages of auto wiring:
  • Overriding possibility – Despite using auto wiring one can still use dependencies like <property> and <constructor-arg> settings, which always can override auto wiring.
  • Primitive data types − one cannot auto wire some simple properties like classes, strings, and primitives etc.
  • Confusing nature – Auto wiring is less exact than explicit wiring and thus it is not preferred if explicit wiring can be used.
There are around twenty modules, which can be categorized into Core Container, Web, Data Access or Integration, Aspect Oriented Programming and Instrumentation and Test.

The modules are:

  • Core module  
  • Bean module
  • SpEL module
  • Context module
  • JDBC (Java DataBase Connectivity)
  • ORM (Object Relational Mapping)
  • OXM (Object XML Mappers)
  • JMS (Java Messaging Service)
  • Transaction
  • Web
  • Web MVC
  • Web Socket
  • Web Portlet
  • Aspect Oriented Programming (AOP)
  • Instrumentation
  • Test
  • Messaging
  • Aspects
AOP or Aspect oriented programming is a technique in programming with the help of which programmers can modularize the crosscutting concerns or change the behavior that cuts across the various divisions of responsibility. Some of the examples of crosscutting concerns are logging well as transaction management. The center of AOP is an aspect. This encapsulates behaviors that can affect multiple classes into modules that can be reused.
A module in spring which contains a set of APIs, which provides for crosscutting requirements is an Aspect. For example, a module that is used in logging is called AOP aspect for logging. Any application can have as many aspects as per requirement.
A spring application consists of the following components:
  • Interface: The functions in spring are defined by the interface.
  • Bean class: It consists of the properties, its setter-getter methods, other functions etc.
  • Spring Aspect Oriented Programming (AOP): In spring AOP provides for the functionality of crosscutting concerns.
  • User program: It uses the function to implement.
Weaving is the process by which aspects can be linked with other application objects for creating the required object.
An Action, which is taken by any aspect at a particular join point, is called an Advice. AOPs use an advice as an interceptor that maintains a train of interceptors near the join point.
Various types of advice are as follows:
  • Before: These are types of advices, which get executed before the join point methods and can be configured using @Before annotation mark.
  • After returning: These are the types of advices which get executed after the join point methods completes executing and the annotation mark used to configure it is @AfterReturning
  • After throwing:  These are the types of advices that execute only and only if join point method returns by exiting an exception and annotation mark used to configure it is @AfterThrowing.
  • After (finally): These are the types of advices which gets executed after a join point method, not concerning whether the method’s exit normally or exceptional return and it can be configured using @After annotation mark.
  • Around: These are the types of advices that get executed before and after a join point and can be configured using the @Around annotation mark.
The differences between Bean Factory and Application Context are as follows:
  • Bean Factory is an interface defined in org.springframework.beansfactory.BeanFactory, while Application Context is an interface defined, is org.springframework.context.ApplicationContext
  • While the former uses lazy initialization the latter uses aggressive initialization
  • While the former explicitly provide for resource object using the syntax the latter creates and manages resource objects on its own
  • The former doesn’t support internationalization while the latter does.
  • The former doesn’t support annotation-based dependency while the latter does.
There are many ways in which Spring Framework can be used. They are listed as follows:
  • It can be used as a full time Spring web application.
  • Using Spring Frameworks middle-tier, it can be used as a third-party web framework.
  • It can be used for remote usage.
  • It can be used as Enterprise Java Bean which has the capability to wrap existing Plain Old Java Objects (POJO)
Join point is a point in an application where one can initialize an AOP aspect. One can also define it as the exact place in the application where an action is said to take place while using spring framework.
The objects, which are most important for the user’s application and are managed by the containers of Spring IoC are called beans. A bean is an object that is initialized, put together, and is managed by a Spring IoC container. The beans are created with the help of configuration metadata that are supplied to the container by the users.

The Spring Framework makes use of five scopes. Three of these scopes are valid only if it is in the form of a web-aware Application Context.

  • Singleton: This is the scope that the bean defines to a single instance for each Spring IoC container.
  • Prototype: This is the scopes that a bean defines to have any number of object instances.
  • Request: This is the scopes that a bean defines as per HTTP requests. This is valid in the form of a web-aware Spring Application Context
  • Session: This is the scopes that a bean defines to an HTTP session. This is valid in the form of a web-aware Spring Application Context
  • Global-session: This is the scopes that a bean defines to a global HTTP session. This is valid in the form of a web-aware Spring Application Context.