Behind the Curtain, part 2

As I mentioned in my prior post, the technology platform for Orange Leap and The Guru is Java, which was a break from what we used in MPX (.NET). One of the strongest advantages to Java was the breadth of web frameworks available to us. We could have used a full JEE stack, Struts, Velocity, SiteMesh, Stripes, or any of a dozen other frameworks. In the end, we decided to go with a full Spring Framework implementation.

The Spring Framework was the Java community’s response to excessive complexity in JEE. What started out as a basic dependency injection framework has morphed into a complete application stack.

Our web pages are implemented using Spring MVC on top of Apache Tiles for page layout. Spring has outstanding support for declarative database transactions via Java annotations, which makes it easy to write services without worrying about manually managing transactions. For example, a method in the ConstituentService to save a new Person entity starts like this:

public Person maintainConstituent(Person person) {

All the magic is enabled in the Spring Application Context XML file, which allows us to keep the code clean. Spring understands the @Transactional annotation, along with numerous others, and makes use of Aspects internally to apply the appropriate behavior around the annotated code.

At the web end of the application, we’re gradually moving our Controllers to be annotation driven. When we first started work on Orange Leap, Spring 2.5 was just coming out and the annotation-driven model was still new. Most of our controllers are “old school” Spring, in that they extend SimpleFormController and are declared as beans in the XML configuration.

But just like the @Transactional annotation makes life easy in the service layer, Spring’s @Controller annotation does the same at the web layer. So instead of having to extend a Spring class and declare the bean in the XML, we simply need to annotate the class that serves as the controller with the appropriate annotation. This contrived examples shows a simple controller which would respond to a request for the URL /hello.htm

public class HelloController {

  public ModelMap sayHello(String name) {

    return new ModelMap("name", name);

I’ve omitted the import statements for brevity, but you can see the power of annotations in simplifying the code. The name parameter could come in as either a POST or GET parameter, such as /hello.htm?name=Tim. Spring will automatically reflect over the incoming parameters and map them to method parameters with the same name. No special configuration is required.

We use a ViewResolver configured in the XML file which maps the requests to JSPs with the same name, passing in the ModelMap for rendering the page.

Now that Spring 2.5 is better understood and appreciated, we have started to migrate our controllers over to the new annotation-drive style. As soon as we get the GA code ready and pushed up to SourceForge, you’ll be able to check it all out for yourself.

I’ll get into how Spring is a good thing for our community in my next post, and also delve into the Tomcat web server.

Explore posts in the same categories: Orange Leap Developer Network

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: