Sunday, May 14, 2006

NFJS - Introduction to Spring

Presented by Stuart Halloway, Relevance, LLC

Stuart is a consultant out of North Carolina. As you will see, I attended many sessions presented by him. He is very dynamic, very knowledgeable, and has a great sense of humor. He also covered lots of Spring topics, which helped as well.

According to Stuart, Spring is Australian for no EJB. As an aside, he said that “having a pulse is Australian for no EJB 1.x or 2.x”. Kind of puts where he is at in perspective.

Spring is a framework that attempts to solve problems typically solved using J2EE, but in a more lightweight fashion. Based on what I heard over the weekend, I tend to agree. At its core, Spring is based on three core concepts. Configuration, Dependency Injection, and Aspect Oriented Programming.

Spring’s answer to configuration may be the most controversial of its features. The basics of a Spring application require minimal code, but the cost of this is large configuration files written in XML. I lost track of the number of times over the weekend a disparaging remark was made about XML. I do wonder why as much as the experts seem to dislike XML, it is still so prevalent. Anyway, if you are going to use Spring, you are going to use XML.

Dependency Injection is the mechanism that allows the details to be encoded in an XML configuration file. DI is based upon the Inversion of Control pattern. The idea is that an object doesn’t “reach out” to get other objects it needs (typically by calling new). Instead, the dependencies are “pushed to” the object from external sources. The means of this injection can be via constructor arguments or via bean-like setters. If the object is designed to depend only upon interfaces, DI can be used to modify object behavior by injecting specialized objects which implement these interfaces. And in Spring, the XML configuration files allow the injected objects to be changed without changing the code.

J2EE also uses an IOC pattern, but realizes it via context or JNDI lookups, which according to Stuart is more cumbersome. Also, evidently Spring minimizes the number of dependencies upon itself, while such dependencies are prolific in J2EE. Never having worked with J2EE, I am parroting what I heard at the seminar. I did find the explanation of Spring much easier to comprehend compared to some J2EE classes I took last year.

The final core component of Spring is Aspect Oriented Programming. If I took nothing else out the symposium, I learned that AOP rocks! I had some exposure to AOP prior to NFJS, but the message was really brought home in Stuart’s talks. I took an entire seminar on Spring and AOP, so I will cover the details in an upcoming blog. Again, the biggest downside to AOP in Spring is the massive XML burden it brings along.

During this talk, Stuart also presented examples of support services provided by Spring. He showed an example using a JDBC that showed how simple it was to connect to a database from a Spring container. He followed that up with a Hibernate example. I am really interested in Hibernate and it is dead easy to use in Spring, but for now, I plan to learn stand-alone Hibernate so that I really understand it well. After that, I will probably explore using it in Spring.

The last topic Stuart covered was Spring’s answer to security, called ACEGI. Again, I took an entire seminar on the topic, and so will reserve the details for a later blog.

No comments: