Spring Interview Questions

Advertisements

Prev Tutorial Next Tutorial

Spring Interview Questions

Spring Interview Questions for Fresher

What is Spring ?

It is a lightweight, loosely coupled and integrated framework for developing enterprise applications in java.

What are the advantages of spring framework ?

Spring framework have following advantage;.

  • Predefined Templates
  • Loose Coupling
  • Easy to test
  • Lightweight
  • Fast Development
  • Powerful Abstraction
  • Declarative support

What are the modules of spring framework ?

Modules of spring framework are given below.

  • Test
  • Spring Core Container
  • AOP, Aspects and Instrumentation
  • Data Access/Integration
  • Web

What is IOC and DI ?

IOC (Inversion of Control) and DI (Dependency Injection) is a design pattern to provide loose coupling. It removes the dependency from the program.

Let's write a code without following IOC and DI.

Example

public class Employee
{  
Address address;  
Employee()
{
address=new Address(); //creating instance  
}  
}  

Now, there is dependency between Employee and Address because Employee is forced to use the same address instance.

Let's write the IOC or DI code.

Example

public class Employee
{
Address address;
Employee(Address address)
{  
this.address=address; //not creating instance  
}  
}  

Now, there is no dependency between Employee and Address because Employee is not forced to use the same address instance. It can use any address instance.

What is the role of IOC container in spring ?

IOC container is responsible to:

  • create the instance
  • configure the instance, and
  • assemble the dependencies

What are the types of IOC container in spring ?

There are two types of IOC containers in spring framework.

  • BeanFactory
  • ApplicationContext

What is the difference between BeanFactory and ApplicationContext ?

BeanFactory is the basic container whereas ApplicationContext is the advanced container. ApplicationContext extends the BeanFactory interface. ApplicationContext provides more facilities than BeanFactory such as integration with spring AOP, message resource handling for i18n etc.

Difference between constructor injection and setter injection

Constructor InjectionSetter Injection
No Partial InjectionPartial Injection
Desn't override the setter propertyOverrides the constructor property if both are defined.
Creates new instance if any modification occursDoesn't create new instance if you change the property value
Better for too many propertiesBetter for few properties.

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

Singleton scope should be used with EJB stateless session bean and prototype scope with EJB stateful session bean.

What are the transaction management supports provided by spring ?

Spring framework provides two type of transaction management supports:

  • Programmatic Transaction Management: Should be used for few transaction operations.
  • Declarative Transaction Management: Should be used for many transaction operations.

What is default scope of bean in Spring framework ?

The default scope of a Spring bean is Singleton scope, you can read this article which explains about all possible scope of a spring bean : What is bean scope in Spring.

Does Spring singleton beans are thread-safe ?

No, Spring singleton beans are not thread-safe. Singleton doesn't mean bean would be thread-safe.

What is dependency Injection ?

Dependency Injection is one of the design pattern, which allows injecting dependency on Object, instead of object resolving the dependency.

What are different implementations of View interface you have used in Spring MVC ?

ULBased View e.g. JSP , JSTLView.

Define Bean Wiring ?

Bean wiring is the creation of associations between application components that are between the beans in a particular spring container.

What is called Spring MVC ?

A Spring MVC is a single shared controller instance and it is used to handle request type controllers, interceptors which run in the IoC container. It also allows multiple Dispatcher Servlets which can share application context interface but not class based interface.

Why Spring framework is needed ?

Spring framework is needed because it is;

  • Very Light Weight Container
  • Framework
  • IOC
  • AOP

What is Auto Wiring ?

Autowiring is used to build relationships between the collaborating beans. Spring container can automatically resolve collaborators for beans.

Differentiate between singleton and prototype bean ?

Singleton means only one bean is defined per object instance while Prototype means one definition to more than one object instances in Spring.

Write about Core container module

Core container module is responsible for the basic functionality of the spring framework. The whole Spring framework is built with this module as a base.

What is a Pointcut ?

Pointcut is used to allow where the advice can be applied.

What is weaving ?

Weaving is used to create new proxy object by applying aspects to target object.

What is difference between singleton and prototype bean ?

Singleton Bean: Single bean definition to a single object instance per Spring IOC container

Prototype Bean :Single bean definition to any number of object instances per Spring IOC Container

What are the different types of AutoProxying ?

  • BeanNameAutoProxyCreator
  • DefaultAdvisorAutoProxyCreator
  • Metadata autoproxying

How can beans be made singleton or prototype ?

The bean tag has an attribute called ‘singleton’. The bean is singleton if its value is ‘TRUE’, otherwise the bean is a prototype.


Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements