Spring Interview Questions Answers
Spring Interview Questions Answers
Answer->
Spring Framework is a powerful lightweight application development framework used for Enterprise Java (JEE).
The core features of the Spring Framework can be used in developing any Java application. It can be described as complete and modular framework.
The Spring Framework can be used for all layer implementations of a real time application. It can also be used for the development of particular layer
of a real time application unlike Struts and Hibernate, but with Spring we can develop all layers.
2.What are the benefits of Spring:
Lightweight: Spring Framework is lightweight with respect to size and transparency.
Inversion Of Control (IOC): In Spring Framework, loose coupling is achieved using Inversion of Control. The objects give their own
dependencies instead of creating or looking for dependent objects.
Aspect Oriented Programming (AOP): By separating application business logic from system services, Spring Framework supports Aspect
Oriented Programming and enables cohesive development.
Container: Spring Framework creates and manages the life cycle and configuration of application objects.
MVC Framework: Spring Framework is a MVC web application framework. This framework is configurable via interfaces and
accommodates multiple view technologies.
Transaction Management: For transaction management, Spring framework provides a generic abstraction layer. It is not tied to J2EE
environments and it can be used in container-less environments.
JDBC Exception Handling: The JDBC abstraction layer of the Spring Framework offers an exception hierarchy, which simplifies the error
handling strategy.
Setter-based DI is realized by calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate
your bean.
Constructor Injection:
Constructor-based DI is realized by invoking a constructor with a number of arguments, each representing a collaborator.
Bean Factory
Bean instantiation/wiring
Application Context
Bean instantiation/wiring
ApplicationEvent publication
So if you need any of the points presented on the Application Context side, you should use ApplicationContext.
6.What is the bean lifecycle? And what are the scopes for the bean?
SCOPE DESCRIPTION
singleton (defau
Single bean object instance per spring IoC container
lt)
prototype Opposite to singleton, it produces a new instance each and every time a bean is requested.
A single instance will be created and available during complete lifecycle of an HTTP request.
request
session A single instance will be created and available during complete lifecycle of an HTTP Session.
Only valid in web-aware Spring ApplicationContext.
A single instance will be created and available during complete lifecycle of ServletContext.
application
Only valid in web-aware Spring ApplicationContext.
A single instance will be created and available during complete lifecycle of WebSocket.
Websocket https://howtodoinjava.com/spring5/core/spring-bean-scopes-tutorial/