July 30, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Spring 2.1 Grows New Features and Evolutionary Enhancements

  • July 11, 2007
  • By Vlad Kofman
  • Send Email »
  • More Articles »

In this article, I will look at the latest and upcoming releases of the Spring Java framework. In one of my previous articles, "Spring: the Eclectic Framework," I discussed the Spring application framework. But since then, Interface21, the company responsible for development and support of the framework, implemented many new features and has released version 2.0 of Spring. The upcoming preview edition 2.1 is already underway, and I will discuss what has changed and improved in this new version over the previous one. Because the Spring framework is an aggregation of various components and modules, its parts have evolved differently, but overall version 2.1 is a major improvement over version 1.x and a sizable improvement over 2.0.

It's good to see that these changes are evolutionary, rather then revolutionary, and are inline with the development trends in the Java community. Among the new enhancements are: support for the Java SE 6 features, integration with JSF, enhancements in the Aspect Oriented Programming (AOP) framework, greater Java Annotations support, more configuration, and bean wiring options (now with Java annotations in addition to XML), as well as a refinement of module for web flow management called Web Flow 1.1. Additionally, Spring 2.1 introduces Portlet MVC framework, integration with Java Persistence API (JPA), and the ability for Spring beans to be implemented in dynamic languages, such as Groovy, JRuby, and Beanshell. There are also further improvements to the core components of Spring—IoC container and Dependency Injection mechanism.

Java Annotations and Spring

Since Java version 1, there were always ways to define specific language behavior using tag metadata. As of Java 5, developers can create custom metadata tags and put them in the code to achieve certain behavior. These custom tags are called annotations. For example, there are three metadata types that are predefined by the Java language specification itself: @Deprecated, @Override, and @SuppressWarnings. An annotation is a special kind of modifier, and can be implemented in situations where other modifiers, such as public, static, or final are used. Annotations can be declared with no value or one or more parameters.

For example, a new annotation can be declared like this:

public @interface Copyright {}

or like this

public @interface Copyright { int yr(); }

and then used with in source code like this:

@Copyright public class Vlad { ... }

Or

@Copyright(2007) public class Vlad { ... }

The definition of annotations is similar to the Java Interface definition, but each method declaration defines an element of the annotation type. Method declarations must not have any parameters or a throws clause. In addition, all return types are restricted to primitives, String, Class, enums, annotations, or arrays of these types.

By definition, annotations have no direct effect on the operation of the code they annotate. So what good do they do? Their usefulness is in their ability to affect the semantics of the running program. This means that they are commands to the compiler (or other tools and libraries) to do something special with the code. For example, the default annotation @SuppressWarnings tells the Jave compiler to ignore and not show any warnings generated by the code annotated by this tag. Similarly, the @deprecated tag indicates that the method marked with it will not be supported in the future, and the compiler needs to generate an appropriate message to the developer.

Spring had some annotations in its early version, but added many more in version 2.0 and even more in version 2.1. Version 1.2 introduced the @Transactional and @ManagedResource tags (for JMX management). Also, the new version adds tags such as, @Configurable, @Required, and @Repository, among others. New annotations within Spring's Aspect Oriented Programming (AOP) are also used to express pointcuts and advices.

I have barely scratched the surface of the annotations because the purpose of this article is to provide an overview. However, if you are interested in gaining more detailed understanding of annotations, I suggest looking at the AspectJ 5 language.

Spring Configuration

The current process of configuring the Spring components is largely done with the XML configuration files. Without proper tools, novice developers may face a steep learning curve when challenged with the task of Spring component configuration and bean "wiring" for the IoC processes. Luckily, more IDEs are coming out to help with configuration task and I will talk about some of them later in this article.

The upcoming 2.1 release will introduce more ways to configure Spring components through annotations in the source code. What this means is that, in addition to the old way of configuring Spring with plain XML, developers will be able to annotate their classes (or beans) with special tags to achieve the same effect. It also will be necessary for the tools' vendors to implement support for this feature so that developers can get the full benefit.

The Spring Web Flow 1.1 Module

Even though Spring is considered a Java web framework, there is really not much in core Spring that would help web developers create web applications. Most of the Spring modules deal with simplification of non-visual aspects or back-end processes of Java programming, such as Inversion of Control, Aspect Oriented Programming, JDBC connections, exception handling, and so forth.

Therefore, it is not surprising that the developers of Spring introduced a separate module dealing primarily with web application flow management. This module is called Spring Web Flow, and is designed to be a framework for web application navigation (not to be confused with MVC). Spring Web Flow is similar in functionality to any modern web framework, such as Struts or Web Work, but different in its packaging. In fact, Spring Web Flow can be integrated with Struts and Java Server Faces (JSF). And, version 1.1 of Web Flow actually has specific features for tighter integration with JSF.

With Web Flow, developers can "set" or create a series of steps based on use-cases, and tie them in easily with the other Spring modules on the back end, or with JSF on the front -end. The flows can be separated into reusable modules, chained as sub-flows, tested in isolation, and deployed to different target containers (such as Servlet or Portlet containers).

Here is an example of a Spring flow:

Figure 1: Spring Web flow diagram

Flows are described using XML, and once created, do not need to be changed when the environment executing them changes. For example, same flow definition should work in the Servlet container and with JUnit, Spring MVC, or Struts. Because flows are configuration based, the Spring IDE includes support for editing and visualizing them graphically. (See more about IDE support later in the article.)

Additionally, here are some more features of the Spring Web Flow module:

  • Automatic garbage collection of memory allocated during flow execution
  • Changes to navigation rules do not require container restart
  • Automatic browser button support (back, forward, refresh)

Both Spring and Spring Web Flow are released under the Apache license.





Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel