Spring Framework

Spring Projects

Spring Project 1

Introduction to Spring Framework

Spring Framework is a Java platform that provides comprehensive infrastructure support for developing Java applications. Spring handles the infrastructure so you can focus on your application.

Spring enables you to build applications from “plain old Java objects” (POJOs) and to apply enterprise services non- invasively to POJOs. This capability applies to the Java SE programming model and to full and partial Java EE. Spring Framework provide the facility to create high performing, easily testable, reusable code.

Learn Spring With Latest Tutorial

Spring framework is an open source Java platform and it was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003. Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.

The core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targets to make J2EE development easier to use and promote good programming practice by enabling a POJO-based programming model.

Need of the Spring?

Spring having much of demand because of the following 3 reasons as

  1. Simplicity: Spring framework is simple because as it is non-invasive, POJO and POJI model.
  2. Testability: Writing the spring application, server [Container] is not mandatory, spring has it own container to run the applications.
  3. Loose Coupling: In spring objects are loosely coupled, this is the core concept of spring framework.
Release Version history

The first version was written by Rod Johnson, who released the framework with the publication of his book Expert One-on-One J2EE Design and Development in October 2002.

The framework was first released under the Apache 2.0 license in June 2003. The first milestone release, 1.0, was released in March 2004, with further milestone releases in September 2004 and March 2005.

The Spring 1.2.6 framework won a Jolt productivity award and a JAX Innovation Award in 2006.

Spring 2.0 was released in October 2006, Spring 2.5 in November 2007, Spring 3.0 in December 2009, Spring 3.1 in December 2011, and Spring 3.2.5 in November 2013.

The current version is Spring Framework 4.0, which was released in December 2013. Notable improvements in Spring 4.0 include support for Java SE 8, Groovy 2, some aspects of Java EE7, and WebSocket.

Examples:

how you as an application developer can make use of the Spring platform and its advantages are:

  1. Make a Java method execute in a database transaction without having to deal with transaction APIs.
  2. Make a local Java method a remote procedure without having to deal with remote APIs.
  3. Make a local Java method a management operation without having to deal with JMX APIs.
  4. Make a local Java method a message handler without having to deal with JMS APIs.
Advantages of Spring Framework

There are many advantages of Spring Framework. They are as follows:

  1. Predefined Templates: Spring framework provides templates for JDBC, Hibernate, JPA etc. technologies. So there is no need to write too much code. It hides the basic steps of these technologies.
  2. Loose Coupling: The Spring applications are loosely coupled because of dependency injection.
  3. 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.
  4. Lightweight: Spring framework is lightweight because of its POJO implementation. The Spring Framework doesn't force the programmer to inherit any class or implement any interface. That is why it is said non-invasive.
  5. Fast Development: The Dependency Injection feature of Spring Framework and it support to various frameworks makes the easy development of JavaEE application.
  6. Powerful abstraction: It provides powerful abstraction to JavaEE specifications such as JMS, JDBC, JPA and JTA.
  7. Declarative support: It provides declarative support for caching, validation, transactions and formatting.
Spring Modules

The Spring Framework includes several modules that provide a range of services

  1. Spring Core Container: This is the base module of Spring and provides spring containers (BeanFactory and ApplicationContext).
  2. Aspect-oriented programming: Enables implementing cross-cutting concerns.
  3. Authentication and authorization: Configurable security processes that support a range of standards, protocols, tools and practices via the Spring Security sub-project (formerly Acegi Security System for Spring).
  4. Convention over configuration: A rapid application development solution for Spring-based enterprise applications is offered in the Spring Roo module.
  5. Data access: Working with relational database management systems on the Java platform using JDBC and object-relational mapping tools and with NoSQL databases.
  6. Inversion of control container: Configuration of application components and lifecycle management of Java objects, done mainly via dependency injection.
  7. Messaging: Configurative registration of message listener objects for transparent message-consumption from message queues via JMS, improvement of message sending over standard JMS APIs
  8. Model–view–controller: A HTTP- and servlet-based framework providing hooks for extension and customization for web applications and REST ful Web services.
  9. Remote access framework: Configurative RPC-style marshalling of Java objects over networks supporting RMI, CORBA and HTTP-based protocols including Web services (SOAP).
  10. Transaction management: Unifies several transaction management APIs and coordinates transactions for Java objects.
  11. Remote management: Configurative exposure and management of Java objects for local or remote configuration via JMX
  12. Testing: Support classes for writing unit tests and integration tests
Features of Spring
  1. Lightweight: spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.
  2. Inversion of control(IOC): The basic concept of the Dependency Injection or Inversion of Control is that, programmer do not need to create the objects, instead just describe how it should be created. No need to directly connect your components and services together in program, instead just describe which services are needed by which components in a configuration file/xml file. The Spring IOC container is then responsible for binding it all up.
  3. Aspect oriented (AOP): Spring supports Aspect oriented programming. Aspect oriented programming refers to the programming paradigm which isolates secondary or supporting functions from the main program's business logic. AOP is a promising technology for separating crosscutting concerns, something usually hard to do in object-oriented programming. The application's modularity is increased in that way and its maintenance becomes significantly easier.
  4. Container: Spring contains and manages the life cycle and configuration of application objects.
  5. MVC Framework: Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.
  6. Transaction Management: Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring's transaction support is not tied to J2EE environments and it can be also used in container less environments.
  7. JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS.
Core Container

The Core Container consists of the Core, Beans, Context, and Expression Language modules.

The Core and Beans modules provide the fundamental parts of the framework, including the IoC and Dependency Injection features.The BeanFactory is a sophisticated implementation of the factory pattern. It removes the need for programmatic singletons and allows you to decouple the configuration and specification of dependencies from your actual program logic.

The Context module builds on the solid base provided by the Core and Beans modules: it is a means to access objects in a framework-style manner that is similar to a JNDI registry. The Context module inherits its features from the Beans module and adds support for internationalization (using, for example, resource bundles), event-propagation, resource-loading, and the transparent creation of contexts by, for example, a servlet container. The Context module also supports Java EE features such as EJB, JMX ,and basic remoting. The ApplicationContext interface is the focal point of the Context module.

The Expression Language module provides a powerful expression language for querying and manipulating an object graph at runtime. It is an extension of the unified expression language (unified EL) as specified in the JSP 2.1 specification. The language supports setting and getting property values, property assignment, method invocation, accessing the context of arrays, collections and indexers, logical and arithmetic operators, named variables, and retrieval of objects by name from Spring's IoC container. It also supports list projection and selection as well as common list aggregations.

Data Access