Spring:
What is Spring or IOC (Inversion of control)?
It is light weight, loosely coupled and integrated Framework.
Improves the testability
Spring components are developed unit testable
Spring makes J2EE easy by using Template.
Advantages:
Layered architecture
Enables Pojo (Plane Old Java Object) programming
Dependency Injection and Inversion of control
IOC means, you no need to create Object, just you have to configured
Open source
Features:
Lightweight
Inversion of control (IOC)
Aspect Oriented Programming(AOP)
MVC framework
Transaction Management
Jdbc Exception Handling
Spring Framework Modules?
Core module
Bean module
Context module
Expression language module
JDBC module
ORM module
Transaction module
Web module
What is Spring Configuration file?
Spring configuration file is an XML file which contains classes information and
Connection details
What is Dependency Injection?
Injection means Injecting One Object into another Object like
Controller -> Service -> Dao->Template ->Session Factory -> Basic Data Source
Coming dependency Injection
We don’t create Objects but describe how they should be created
We don’t directly connect the components and services together in code
But, describe which service are needed by which components in configuration file
Container is responsible for doing it.
Dependency makes our programming code loosely coupled.
How many Types of Injection have in Spring?
Setter, Constructor and Interface Injections.
But, Spring Supports Setter and Constructor Injections Only
Constructor Injection:
There is no partial Injection
It doesn’t override Setter property
It ‘ll create new instance, if any modifications done.
It is better for few properties
Setter Injection:
There can be partial injection
It overrides the constructor property
It won’t create new instance if any modifications are done
It is better for too many properties
Note: When we use Constructor dependency, then if A depends on B and B depends on A it is called
Cyclic Dependency Injection.
Bean Life Cycle?
Spring MVC Flow:
Request first comes Client to Dispatcher Servlet
Then request goes to Handler mapping, it maps the request to particular
Controller class
Then request goes to Controller -> Service-> Dao (Data access Object)
It returns ModelAndView Object to dispatcher servlet
It sends View name to view resolver
It returns view to dispatcher servlet
dispatcher servlet model object return to View Object
View return response to dispatcher servlet
Dispatcher servlet send response to Client.
Difference between Bean Factory and Application Context?
Bean Factory:
Uses Lazy Initialization
Explicitly provides a resource Object using the syntax
Doesn’t support internalization
Annotation based dependency injection is not supported
it constructs the Object when the request comes.
Application Context:
uses eager initialization
creates and manages resources objects on its own
support internalization
annotation based dependency injection is supported
it constructs the Objects even when we don’t have request
Note: Internalization means, if you create any application if it is working only in your
machine then it is not internalization, if it is works any machine and anywhere it is called
Internalization.
What is IOC?
It is Spring framework
IOC is a Spring Container
The container will create the Objects,
Wire then together,
Configure them,
And manage tier complete life cycle form Objects creation to till destruction.