Spring Framework - Notes Prepared
Spring Framework - Notes Prepared
Spring Framework - Notes Prepared
The Spring framework comprises several modules such as IOC, AOP, DAO,
Context, ORM, WEB MVC etc.
These are the design patterns that are used to remove dependency from the
programming code
They make the code easier to test and maintain. Let's understand this with the
following code:
class Employee{
Address address;
Employee(){
address=new Address();
}
}
In such case, there is dependency between the Employee and Address (tight
coupling). In the Inversion of Control scenario, we do this something like this:
class Employee{
Address address;
Employee(Address address){
this.address=address;
}
}
Thus, IOC makes the code loosely coupled. In such case, there is no need to
modify the code if our logic is moved to new environment
Advantages of Spring Framework
Predefined Templates: (SF provides template for JDBC, Hibernate, JPA etc.)
Easy to test: (The Dependency Injection makes easier to test the application. The
EJB or Struts application require server to run the application but Spring
framework doesn't require server)
IoC Container:
The IoC container gets informations from the XML file and works accordingly
1. BeanFactory
2. ApplicationContext
Both are interface act as the IOC container.
Bean Factory:
Using ApplicationContext: