Spring is an open source framework or light weight framework for the development of enterprise applications. Many developers use spring to create high performing, easily testable, reusable code without any lock in. Spring framework works in modular fashion that means it permits to use in parts and leave the other component which is not used by the current application.
Investment and retail banking organizations, well-known dotcoms, global consultancies, academic institutions, government departments, defense contractors, several airlines, scientific research organizations etc are the users of spring. Spring is unique because,
The spring framework implements Inversion-of-Control and Aspect Oriented Programming mechanism. The key points here are “layered application framework” and “Inversion of Control and Aspect Oriented Programming.” These can be divided into two broad categories:
The former refers to the design patterns supported by Spring Framework and the latter refers to the components that build up the Framework.
Spring has two patterns at its core. They are:
The former is also called IoC and the latter is known as AOP. Here are the details.
Inversion-of-Control is called IoC for short. IoC “is a concept, and an associated set of programming techniques, in which the control flow is inverted compared to the traditional interaction model expressed in imperative style by a series of procedure calls.” In other words, the framework calls the procedures created by the programmer, rather than programmer calling the procedures or methods of the framework. IoC is used to ‘inject’ dependencies at runtime. When one uses this pattern, the dependencies of a particular object are not satisfied at compile time. Instead, the framework provides the required dependencies to the object at runtime. Thus, this pattern releases the programmer from the chore of providing all the dependencies at compile time.
Aspect Oriented Programming or AOP for short, is by definition “An approach to programming that attempts the separation of concerns, specifically cross-cutting concerns, as an advance in modularization.” Here, the key point is separation of concerns. Concern is another term for a module of an application, where module refers to a functionality of the application.
Separation of concerns means that the applications are divided into modules that do not overlap in terms of functionality. However, some functionalities or modules/concerns always overlap other modules/concerns. Logging is an example of such a concern. AOP provides techniques to encapsulate cross cutting or overlapping concerns. In other words, by using AOP a developer can encapsulate cross cutting concerns.
Spring provides both IoC as well as AOP. They are built into the core of the Spring Framework. The next aspect of the Spring Framework worth noting is its support for layered architecture. It provides this support through its various components. Some of them are:
These three cater to the Presentation, Business, and Persistence layers. Here is a brief overview:
That completes the bird’s eye view of the Spring Framework. Next, let us have a look at the steps involved in using the Spring Framework, specifically the IoC capability of the Spring Framework.
Spring framework is a layered architecture and this architecture consists of seven modules. The modules of spring framework are built on the top of the container, which defines how beans are created, configured, and managed.
The modules in the spring frame work are,
The one AOP framework is the one of the key components of spring. The Spring AOP module integrates aspect-oriented programming functionality directly into the spring framework, through its configuration management feature. As a result you can easily AOP-enable any object managed by the spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components.
The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply with spring’s generic transaction and DAO exception hierarchies. The ORM package is related to the database access.
The Web context module builds on top of the application context module, providing contexts for Web-based applications. The spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects. This module is a part of spring web application development stack, which includes Spring MVC.
The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring DAO’s JDBC-oriented exceptions comply with its generic DAO exception hierarchy. So we can say that the DAO support in spring primarily for standardizing the data access work using the technologies like JDBC, Hibernate or JDO.
It is a configuration file that gives context information to the spring framework. The spring context consists of enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality. This package creates on the beans package to add support for message sources and for the Observer design pattern, and the ability for application objects to obtain resources using a consistent API.
The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI.
The core container provides the essential functionality of the spring framework. A primary component of the core container is the
BeanFactory, an implementation of the Factory pattern. The
BeanFactory applies the Inversion of Control (IOC) pattern to separate an application’s configuration and dependency specification from the actual application code
Advantages of Spring Framework