Simple Spring Example Project
The Spring framework is not new, it’s been around since mid 2003. In very simple terms Spring is a framework to help build Java (and .NET) applications. Spring helps organize and orchestrate the source code for Java applications. Spring can be used with any Java application including Java web applications.
This is beneficial to Flex applications that communicate with server side Java web applications. In addition, Flex developers can now use the new Spring BlazeDS Integration provided by Spring with BlazeDS projects. Check out the awesome blog post and video by Christophe Coenraets for a walk through of the Spring BlazeDS Integration. His example project should get you up and running pretty quickly.
After reviewing the example that Chris provided I wanted to take things s step further and integrate Hibernate and MySQL into the project. I wrestled with the JAR’s, the classpath, the Spring and Hibernate XML markup, and the Hibernate Annotations for a while and then realized that I needed to get a firm understanding of some Spring fundamentals. Manning’s Spring in Action was recommended by a colleague and so far has been really shedding some light.
I was able to create a simple Spring project (no Flex, no BlazeDS, no Hibernate… yet) to help me understand some of the core Spring concepts. The IoC Container and AOP are two very important pieces of the Spring framework. This very simple project only utilizes the IoC Container. Aspect Oriented Programming is very cool and I also recommend checking it out. AOP is not covered in this example. (Check out cross cutting concerns.)
There is a simple Ant task to compile, jar and run the application. You’ll also need the latest version of the JDK for this application.
You can download the project using a Subversion client using the following URL:
http://seantheflexguy.com/applicationcontextex/
You can also download a zipped version of the project here:
http://seantheflexguy.com/java/ApplicationContextExample.zip
To run the project navigate to the directory where you downloaded the project, and extracted if you grabbed the zip. Then from the project root using a Terminal or Command Prompt issue the command: ant to compile and: ant run to run the application.
The first version of the application used a BeanFactory. This second version uses the ApplicationContext class instead. BeanFactory is in Spring’s core module, it’s the main Spring container that provides DI. The ApplicationContext module builds on BeanFactory providing additional capabilities such as: internationalization and validation support and access to the application event lifecycle.
The Simple Spring Example Project should help you understand the most basic level Spring mechanics. The only JARs required by the project are spring.jar and the commons-logging-1.1.1.jar, both are included with the project. The Ant build file will set the CLASSPATH for these JARs, if you bypass Ant make sure to set these on the CLASSPATH prior to compiling the application.
So far Spring really looks like a powerful way to organize and manage Java application development. You should take a moment to check it out. Also be sure to check out the Spring BlazeDS Integration.
flickr
brightkite
[...] Simple Spring Example Project [...]