Spring framework is a light weight open source layered application framework created to simplify the complexity of enterprise application development. Spring has become the de facto framework for creating Java based enterprise applications.
The Spring framework provides the following functionality:
Light weight IoC container for lifecycle and dependency management of objects.
AOP functionality for modularizing cross-cutting concerns and providing services to POJO in a declarative fashion, like transaction management, logging, messaging, exposing POJO using one of the remote technology like RMI, HTTP, web services, and so on.
Consistent abstraction layer which provides integration with various standards like JPA (Java Persistence API), JDBC, JMS, and third party APIs like Hibernate, Top Link, and JDO.
MVC framework which provides a highly configurable Model View Controller implementation via strategy interfaces, and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, andPOI implementation.
Spring framework assists in POJO development where all the features described above can be applied to POJO and the Spring IoC container provides the necessary infrastructure to assemble POJOs to create the required application.
The core of Spring's design is the org.springframework.beans
package, designed for working with beans. The package serves as the underlying medium for other functionality and is typically not used by developers. The next layer of abstraction is the org.springframework.beans.factory.BeanFactory
interface which is the root interface for accessing the Spring IoC container. An implementation of BeanFactory
enables you to access the objects that are instantiated and managed by the Spring IoC container.
The most commonly used BeanFactory
definition is the XmlBeanFactory
which loads beans based on definitions in an XML file, as shown in code listing below:
BeanFactory factory = new XMLBeanFactory(new FileInputSteam("beans.xml"));
To retrieve a bean from BeanFactory you simply call the getBean()
method: passing in the name of the bean you want to retrieve, as shown in listing below
OrderBean orderbean = (MyBean) factory.getBean("order");
Next we look at IoC concepts in action by taking an example of a Loan processing system. The following example should be sufficient to understand the concepts of IoC used in the context of the book.