Home > Spring Framework Primer > Spring Framework Primer

Spring Framework Primer

 

 

 

  

  

Spring Framework Primer 

The Spring Framework is an open source application framework, for the Java platform and also the .NET Framework (Spring.NET). 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 Spring 1.2.6 framework won a Jolt productivity award and a JAX Innovation Award in 2006. The current Spring framework version is 3.0.

VMware acquired SpringSource for approximately $362 million on September 16, 2009.

Spring was created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components or modules you want to use for your application development. Unlike single-tier frameworks, such as Struts or Hibernate, Spring aims to help structure whole applications in a consistent, productive manner, pulling together best-of-breed single-tier frameworks to create a coherent architecture.

The core features of the Spring Framework can be used by any Java application, but there are extensions for building web applications on top of the Java Enterprise platform. Although the Spring Framework does not impose any specific programming model, it has become popular in the Java community as an alternative, replacement, or even addition to the Enterprise JavaBean (EJB) model.

 

Spring is unique for several reasons:

  • It addresses important areas that other popular frameworks don’t. Spring focuses around providing a way to manage your business objects.
  • Spring is comprehensive and modular (because of its modules). Spring has a layered architecture, meaning that you can choose to use just about any part of it in isolation, yet its architecture is internally consistent. So you get maximum value from your learning curve. For example: You might choose to use Spring only to simplify use of JDBC, or you might choose to use Spring to manage all your business objects. 
  • It’s easy to introduce Spring incrementally into existing projects.
  • Spring is designed from the ground up to help you write code that’s easy to test. Spring is an ideal framework for test driven projects.
  • Spring is an increasingly important integration technology, its role is recognized by vendors both large and small.
  • Spring also addresses most infrastructure concerns (cross-cutting concerns such as logging, security etc) of typical applications.

 

  

Architectural benefits of Spring:

Let’s look at some of the benefits Spring can bring to your project:

  • Spring can effectively organize your middle tier objects. Spring takes care of plumbing that would be left up to you if you use only Struts or any other framework that use J2EE APIs.
  • Spring’s configuration management services can be used in any architectural layer, in whatever runtime environment.
  • Spring can eliminate the increase of Singletons used in many projects. This is a major problem that reduces testability and object orientation.
  • Spring eliminates the need to use a variety of custom properties file formats, by handling configuration in a consistent way throughout the application.
  • Spring facilitates good programming practice by reducing the cost of programming to interfaces rather than classes.
  • 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.
  • Applications built using Spring are very easy to test. For certain unit testing scenarios, the Spring Framework provides mock objects and testing support classes. Spring also provides unique “integration testing” functionality in the form of the Spring TestContext Framework and legacy JUnit 3.8 support classes that enable you to test your code quickly and easily, even while accessing a staging database.
  • Spring helps you solve problems though being a most lightweight possible infrastructure. Spring provides 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.
  • Spring provides a consistent framework for data access, whether using JDBC or an O/R mapping product such as TopLink, Hibernate or a JPA or JDO implementation.

 

Spring is essentially a technology dedicated to enable building applications using Plain Old Java Objects (POJOs). It enables you to develop components as POJOs containing only your business logic, while the framework takes care of the many value adds you need while building enterprise applications — even in areas that you may not have considered when initially authoring the application. This goal requires a sophisticated framework, which conceals much complexity from the developer.

Since your business logic is abstracted from infrastructure concerns, it’s also likely to enjoy a longer life. As the business logic is abstracted from the infrastructure concerns, any changes to the inevitable infrastructure change (such as choice of application server) can be minimized. Thus Spring can enable you to implement the simplest possible solution to your problems. And that’s worth a lot.

 

What does Spring do? 

Spring’s main aim is to make enterprise Java easier to use and promote good programming practices. It does this by enabling a POJO-based programming model that is applicable in a wide range of environments. Spring provides the ultimate programming model for modern enterprise Java.  Spring is a powerful framework that solves many common problems in enterprise Java. Most Spring features are also usable in a wide range of Java environments, beyond classic Java EE.

Spring does not re-invent the wheel. Thus you’ll find no logging packages in Spring, no connection pools, no distributed transaction coordinator. All these things are provided by open source projects (such as Commons Logging, which is used for all log output), or by your application server or web container. For the same reason, Spring doesn’t provide an O/R mapping layer because there are already good solutions to this problem such as TopLink, Hibernate, JPA and JDO.

Spring does aim to make existing technologies easier to use and does aim to provide a unified, simple yet powerful programming model. For example, although Spring is not in the business of low-level transaction coordination, it provides an abstraction layer over JTA or any other transaction strategy, that is more portable, easier to use and makes code easier to test.

Spring provides a unique data access abstraction, including a simple and productive JDBC framework that greatly improves productivity and reduces the likelihood of errors. Spring’s data access architecture also integrates with TopLink, Hibernate, JDO, JPA and other O/R mapping solutions. Spring also provides a unique transaction management abstraction, which enables a consistent programming model over a variety of underlying transaction technologies, such as JTA or JDBC.

Spring is portable between application servers and web containers. (Indeed, its core functionality does not require another container). Of course ensuring portability is always a challenge, but Spring avoids anything platform-specific or non-standard in the developer’s view, and support users on WebLogic, Tomcat, Resin, JBoss, Jetty, Geronimo, WebSphere and other application servers. Spring’s non-invasive, POJO approach enables us to take advantage of environment-specific features without sacrificing portability, as in the case of enhanced WebLogic, WebSphere and OC4J transaction management functionality that uses BEA and IBM proprietary APIs under the covers.

Spring provides a consistent way of managing business objects and encourages good practices such as programming to interfaces, rather than classes. The architectural basis of Spring is an Inversion of Control container designed to configure any POJO. However, this is only part of the overall picture: Spring is unique in that it uses its IoC container as the basic building block in a comprehensive solution that addresses all architectural tiers.

Spring provides an AOP framework written in standard Java, which provides declarative transaction management and other enterprise services to be applied to POJOs or – if you wish – the ability to implement your own custom aspects. This framework is powerful enough to enable many applications to dispense with the complexity of EJB, while enjoying key services traditionally associated with EJB.

Spring also provides a powerful and flexible MVC web framework that is integrated into the overall IoC container. Numerous other enterprise services, such as remoting and JMX integration, are offered out of the box.

  

Spring and Java versions:

While many new features (such as annotation-based programming styles) require Java features introduced in version 5.0, as of Spring 2.5, all core functionality is still available in applications using Java 1.4. This is important to users of older application servers, who do not need to upgrade their production environments to take advantage of a productive modern programming model.

New Java 6-specific features include:

  • JDBC 4.0: Jdbc4NativeJdbcExtractor, support for extended DataSource interface
  • JMX MXBean support: server-side export and client-side proxying of MXBeans
  • ServiceLoader API: making services discovered via META-INF/services available for dependency injection
  • JAX-WS support: including support for service exposure via the built-in web server in JDK 1.6

  

The future:

One of the key benefits of Dependency Injection is that your code can not merely be configured in an environment it does not depend on explicitly, but can benefit from services that were not envisaged at its time of authoring. Thus Spring offers a flexible component model that can offer a variety of value adds for little or no effort. For example:

  • You can “export” any Spring-managed object as a JMX MBean without writing Java code.
  • Spring Dynamic Modules for OSGi™ Service Platforms allows Spring to take advantage of the powerful modularization capabilities of OSGi, without business objects needing to depend on OSGi APIs or an OSGi runtime.
  • Spring’s compatibility with the SCA SOA standard makes Spring managed objects “SCA ready”. SCA specifies a Spring binding for Java.
  • Spring integrates with a range of clustering and grid solutions such as GigaSpaces, Oracle Coherence and Terracotta.
  • Your code can take advantage of Spring’s rich and deepening range of platform integrations, while remaining free of proprietary extensions. For example, in a WebLogic environment, you gain sophisticated transaction monitoring functionality due to the fact that Spring ties into BEA APIs, without writing a line of WebLogic-specific code in your application.

Spring moves forward rapidly, and development activity is further accelerating, so the range of value adds available continues to grow.

 

 

  

NoteRefer to other posts in Spring Framework category for further knowledge.

  

Source: Introduction to Spring Framework 2.5 by Rod Johnson, The ServerSide.COM and Wikipedia.

 

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: