SpringIDE - Using Spring in Eclipse
The following article introduces SpringIDE - a set of plugins to simplify development of Spring based applications in Eclipse. I'll cover how to get started with Spring and how to write a simple Spring AOP example.
Spring in a Nutshell
For a consise introduction to Spring, this article on TheServerSide is a good start. In a nutshell, Spring allows you to use Plain Old Java Objects (POJO's) to build an application. You create an XML configuration file to 'wire up' any POJOs that act as beans. These beans can then reside in the Spring container. The most interesting part for me was Spring AOP (Aspect Oriented Programming), which provides 'interceptors' so that I can do something to change the state of the application before or after a particlar method is called.
This was a key feature for me - at the time I wanted to write some aspects to confirm that data could not be corrupted in some safety critical code in my application. Rather than using a seperate AspectJ compiler - the opportunity to have these checks available at runtime was perfect for me. Any sections of the code that I wanted to intercept were converted to POJOs which I then included in my Spring configuration file. Once I wrote up the interceptors, I was ready to test my application's stability thanks to Aspects.
SpringIDE wasn't available when I wrote this code, so I had to write my configuration files in a plain old text editor, and had to validate them by trial and (a lot of!) error, running the application to find what I had done wrong. Thankfully, that job is a lot easier with the latest version of SpringIDE.
SpringIDE provides a user interface for Spring configuration files, built as a set of plugins on the Eclipse
platform. The IDE provides a wizard for creating Spring projects, and using the Graphical Editing Framework, displays graphs of all beans and relationships either within a single configuration file or within a set of configuration files. The files, or sets, are also validated as they are added/modified. There's also support for Spring AOP, so pointcut expressions are validated in your Spring configuration. You can also see a visualisation of your AOP configuration.
The Aim of this Example
Before we get started, I'm going to outline the aim of this example. I want to monitor each time a method is called in a particular object. While doing this, I should have the opportunity to change the input that the method gets. I'll show how Spring helps us to do this, and I will use the SpringIDE tools to implement the example.
Before starting ensure that you have the following installed:
- Eclipse 3.3 with WTP - http://www.eclipse.org/downloads/moreinfo/jee.php
- Spring Framework - http://www.springframework.org/download
For completeness, it's best if you install the version with depedencies
Once Eclipse is up and running, use the Eclipse Software Update wizard to go to the SpringIDE update site to download the latest version (http://springide.org/updatesite-dev).