Spring Framework : A Framework from SpringSource :: Introduction
- What is Spring?
- What is AOP.
- What is IoC?
- Architecture of Spring.
- Features of Spring.
- Versions of Spring Framework.
- Spring 1.2 Overview and new features in Spring 2.0 Overview
- Benefits of Spring Technology
- Download Spring API Documentation.
What is Spring? |
- Before the advent of Enterprise JavaBeans [ EJB], Java Developers used JavaBeans to create Web Applications. Although JavaBeans are reusable software components used to hold view data in an application., it was not able to provide services such as transaction management, security, which are required to develop robust and secure enterprise application.
- The Advent of EJB was seen as a solution of this problem. but developing an enterprise application with EJB was not easy. As a java developer had to perform various task such as creating Home and Remote interfaces and implementing lifecycle callback methods, which led to Complexity. To overcome the complexity, Java Developers searched for an easier way to develop Enterprise Applications.
NOW
- The Spring Framework is introduced as a solution of these complications. This framework uses various new techniques, such as AOP [ Aspect Oriented Programming ] , [ POJO ] Plain Old Java Object , and Dependency Injection [ DI ], to develop Enterprise Applications, consequently removing the complexity involved while creating Enterprise Applications.
- Spring is an Open source, lightweight framework that allows Java Developers to build simple, reliable, and scalable enterprise application. it helps to manage business object by various ways.
- Unlike , single-tier frameworks, such as Struts and Hibernate, Spring aims at helping to structure an enterprise application in a consistent and productive manner by putting together the useful features of single-tier framework to create a coherent architecture.
- The Struts Framework enhances the ability of the we tier that implements the presentation layer of an application and leaves the implementation of the business logic of middle tier to Java Developers.
- The Spring Framework provides a solution to this problem as it includes a MVC [ Model View Controller ] framework, an AOP integration framework, a JDBC integration framework, and an EJB integration framework.
- It also provides integration modules for O/R Mapping tools such as , Hibernate, JDO [ Java Database Object ], and iBatis.
What is AOP. |
- It is similar to Object Oriented Programming [OOP], which decomposes application into a hierarchy of objects, and AOP decomposes programs into aspects or concerns. The Spring AOP Module allows us to implement concerns or aspects in a Spring application.
- In the Spring AOP module, aspects are regular spring beans or classes annotated with the @Aspect annotation.
- These aspects help in transaction management, logging, and failure monitoring.
- Transaction management, for example, is required in bank to transfer an amount from an account to another. The Spring AOP module provides a transaction management abstraction layer, which can be applied to transaction APIs to facilitate transaction management in an application.
What is IoC? |
- IoC Container OR Inversion of Control :- It uses the DI or Ioc pattern to implicitly provide an object reference in a class during runtime. This pattern acts as an alternative to the service locator pattern, used to hide the complexities, such as lookup and initial context creation.
- The Ioc Container, which is also known as Core Container, contains assemble code, which handles the configuration management of application objects.
- The Spring Framework provides two packages, org.springframework.beans and org.springframework.context, which help to provide the functionality of the IoC container in an application.
BeanFactory or ApplicationContext?
- Users are sometimes unsure whether a BeanFactory or an ApplicationContext is best suited for use in a particular situation.
- A BeanFactory pretty much just instantiates and configures beans.
- An ApplicationContext also does that, and it provides the supporting infrastructure to enable lots of enterprise-specific features such as transactions and AOP.
In short, favor the use of an ApplicationContext.
- The org.springframework.beans and org.springframework.context packages provide the basis for the Spring Framework’s IoC container.
- The BeanFactory interface provides an advanced configuration mechanism capable of managing objects of any nature.
- The ApplicationContext interface builds on top of the BeanFactory (it is a sub-interface) and adds other functionality such as easier integration with Spring’s AOP features, message resource handling (for use in internationalization), event propagation, and application-layer specific contexts such as the WebApplicationContext for use in web applications.
- In short, the BeanFactory provides the configuration framework and basic functionality, while the ApplicationContext adds more enterprise-centric functionality to it. The ApplicationContext is a complete superset of the BeanFactory, and any description of BeanFactory capabilities and behavior is to be considered to apply to the ApplicationContext as well.
- The IoC component of the Spring Framework addresses the enterprise concern of taking the classes, objects, and services that are to compose an application, by providing a formalized means of composing these various disparate components into a fully working application ready for use.
- The Spring Framework takes best practices that have been proven over the years in numerous applications and formalized as design patterns, and actually codifies these patterns as first class objects that you as an architect and developer can take away and integrate into your own application(s). This is a Very Good Thing Indeed as attested to by the numerous organizations and institutions that have used the Spring Framework to engineer robust, maintainable applications.
Architecture of Spring. |
The Spring Framework contains a lot of features, which are well-organized in six modules shown in the following diagram.
The Core package
is the most fundamental part of the framework and provides the IoC and Dependency Injection features. The basic concept here is the BeanFactory, which provides a sophisticated implementation of the factory pattern which removes the need for programmatic singletons and allows you to decouple the configuration and specification of dependencies from your actual program logic.
The Context package
build on the solid base provided by the Core package: it provides a way to access objects in a framework-style manner in a fashion somewhat reminiscent of a JNDI-registry. The context package inherits its features from the beans package and adds support for internationalization (I18N) (using for example resource bundles), event-propagation, resource-loading, and the transparent creation of contexts by, for example, a servlet container.
The DAO package
provides a JDBC-abstraction layer that removes the need to do tedious JDBC coding and parsing of database-vendor specific error codes. Also, the JDBC package provides a way to do programmatic as well as declarative transaction management, not only for classes implementing special interfaces, but for all your POJOs (plain old Java objects).
The ORM package
provides integration layers for popular object-relational mapping APIs, including JPA, JDO, Hibernate, and iBatis. Using the ORM package you can use all those O/R-mappers in combination with all the other features Spring offers, such as the simple declarative transaction management feature mentioned previously.
Spring’s AOP package
provides an AOP Alliance-compliant aspect-oriented programming implementation allowing you to define, for example, method-interceptors and pointcuts to cleanly decouple code implementing functionality that should logically speaking be separated. Using source-level metadata functionality you can also incorporate all kinds of behavioral information into your code, in a manner similar to that of .NET attributes.
Spring’s Web package
provides basic web-oriented integration features, such as multipart file-upload functionality, the initialization of the IoC container using servlet listeners and a web-oriented application context. When using Spring together with WebWork or Struts, this is the package to integrate with.
Spring’s MVC package
provides a Model-View-Controller (MVC) implementation for web-applications. Spring’s MVC framework is not just any old implementation; it provides a clean separation between domain model code and web forms, and allows you to use all the other features of the Spring Framework.
Features of Spring |
Features of Spring framework are as following
- IoC Container
- Data Access Framework
- Spring MVC Framework
- Transaction Management
- Spring Web Services
Versions of Spring Framework |
Spring Framework Versions
Current Releases
- Spring Framework 5.0, Spring requires JDK 8+ (Java SE 8+) and provides out-of-the-box support for JDK 9 already.
- Spring Framework 4.0 ( released in December 2013 )
- Spring 3.2.5 in November 2013
- Spring 3.1 in December 2011,
- Spring Framework 3.0 ( release 3.0.5)
- Spring Framework 2.5 ( release 2.5.6)
Previous Releases
- Spring Framework 2.0 (production version 2.0.8)
- Spring Framework 1.2 (production version 1.2.9)
- Spring Framework 1.1 (production version 1.1.5)
Spring 1.2 Overview and new features in Spring 2.0 Overview |
Spring 1.2 Overview and new features in Spring 2.0 Overview
Spring 2.0 provides a wide range of enhancements, of which the most visible are as follows:
Configuration extensions
- In Spring 2.0, Spring supports extensible XML configuration, enabling the development of custom elements that offer a new level of abstraction for generating Spring bean definitions.
- The XML extension mechanism also allows the provision of new tags to simplify many common tasks.
- Major enhancements in the AOP framework, which make it both more powerful and easier to use.
- Enhanced support for Java 5.
- The ability for Spring beans to be implemented in dynamic languages, such as Groovy, JRuby and Beanshell, while retaining all the services of the Spring component model, such as Dependency Injection, out of the box declarative services and AOP.
- Many new features including a Portlet MVC framework, “message driven POJOs,” integration with new APIs including the Java Persistence API (JPA) and an asynchronous task execution framework.
A number of features below the surface are less evident, but still important:
- Further IoC container extension points that make it easy to build frameworks or products on top of Spring.
- Improvements in Spring’s unique integration testing support.
- The provision of AspectJ aspects exposing core Spring functionality such as transaction management and Dependency Injection to users using both AspectJ and Spring.
Benefits of Spring Technology |
Before you get down to specifics, the benefits of Spring technology are as follows:
- Applications built using Spring are very easy to unit test.
- Spring can facilitate good programming practice by reducing the cost of programming to interfaces, rather than classes, almost to zero.
- Spring can effectively organize your middle tier objects, whether or not you choose to use EJB. Spring takes care of plumbing that would be left up to you if you use only Struts or other frameworks geared to particular J2EE APIs. While it is perhaps most valuable in the middle tier, Spring’s configuration management services can be used in any architectural layer, in whatever run time environment.
- Spring provides a consistent framework for data access, whether using JDBC or an O/R mapping product such as TopLink, Hibernate or a JDO implementation.
- Spring can eliminate the proliferation of singletons seen on many projects. This is a major problem, as it reduces testability and object orientation.
- Spring can eliminate the need to use a variety of custom properties file formats, by handling configuration in a consistent way throughout applications and projects. Ever wondered what magic property keys or system properties a particular class looks for, and had to read the Javadoc or even source code? With Spring you simply look at the class’s JavaBean properties or constructor arguments. The use of Inversion of Control and Dependency Injection (discussed below) helps to achieve this simplification.
- Spring is designed so that applications built with it depend on as few of its APIs as possible. Most business objects in Spring applications have no dependency on Spring.
- Spring can make the use of EJB an implementation choice, rather than the determinant of application architecture. You can choose to implement business interfaces as POJOs or local EJBs without affecting calling code.
- Spring helps you to solve many problems without using EJB. Spring can provide an alternative to EJB that’s appropriate for many applications. For example, Spring can use AOP to deliver declarative transaction management without using an EJB container; even without a JTA implementation, if you only need to work with a single database.
- Spring provides a consistent, simple programming model in many areas, making it an ideal architectural “glue.” You can see this consistency in the Spring approach to JDBC, JMS, JavaMail, JNDI, and many other important APIs.
Download Spring API
1. Spring 2.5 API Documentation
2. Spring 3.0 API Documentation
Recent Comments