Using Spring BlazeDS Integration 1.0.0.M1

Today we announced the public availability of the first milestone release of the newest member of the open source Spring project portfolio, Spring BlazeDS Integration. This project's purpose is to make it easier to build Spring-powered Rich Internet Applications using Adobe Flex as the front-end client. It aims to achieve this purpose by providing first-class support for using the open source Adobe BlazeDS project and its powerful remoting and messaging facilities in combination with the familiar Spring programming model.
This first milestone is very much a foundational release, focusing on support for configuring and bootstrapping the BlazeDS MessageBroker (the central component that handles incoming messages from the Flex client) as a Spring-managed object, routing HTTP messages to it through the Spring DispatcherServlet infrastructure, and easily exporting Spring beans as destinations for direct Flex remoting. Future milestones leading up to the final 1.0 will build upon this foundation to provide deeper features such as Spring Security integration, messaging integration using Spring's JMS support, an AMFView for use in conjunction with Spring 3.0's REST support, and hopefully further things to address the needs of our community that we haven't thought of yet. This milestone is also our first opportunity to invite the community to get involved by trying out the release and providing feedback in the project Jira and new community forum.
Taking Spring BlazeDS Integration for a Test Drive
The BlazeDS project comes with a number of excellent "test drive" sample applications to help in understanding how to build Flex applications that take advantage of BlazeDS's remoting and messaging capabilities. These samples use the BlazeDS MessageBrokerServlet to route messages through to BlazeDS-managed Java objects that are wired together using the BlazeDS-specific XML configuration. Sounds great, but what about your existing Spring-based infrastructure? Wouldn't it be nice if you could take advantage of the capabilities of the MessageBroker without having to configure a separate servlet and by using the familiar Spring programming model? This is where Spring BlazeDS Integration fits into the picture.
I've created a modified version of the BlazeDS test drive sample app that uses Spring BlazeDS Integration. The full source of the modified sample is available here. You should be able to import the sample into Eclipse and run it using WTP. Once the app is deployed successfully, you can access the individual test drive samples at http://localhost:8080/samples/testdrive.htm. (Note that before starting the app, you must start the included HSQL demo database in /sampledb.) Here I'll walk through some of the more interesting pieces of the sample to illustrate what is needed to get started in building Spring-powered Flex applications.
The first thing worth taking a look at in the project is /samples/WEB-INF/web.xml. Here you will see a fairly typical setup for the Spring DispatcherServlet:
<!-- The front controller of this Spring Web application -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/web-application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all /spring requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
This takes the place of the MessageBrokerServlet configuration in the standard BlazeDS samples. This particular application is set up with a mapping strategy that would allow serving of both Flex direct remoting content and RESTful content from the same application. If you were building an app that only targeted Flex clients, you could use a simpler mapping strategy as discussed in the reference manual.
The next piece to take a look at is the Spring configuration in /samples/WEB-INF/config/web-application-config.xml. First, notice the MessageBrokerFactoryBean definition:
<!-- Bootstraps and exposes the BlazeDS MessageBroker -->
<bean id="mySpringManagedMessageBroker"
class="org.springframework.flex.messaging.MessageBrokerFactoryBean" />
This bootstraps the BlazeDS MessageBroker as a Spring-managed bean, using a default location of /samples/WEB-INF/flex/services-config.xml for the BlazeDS configuration. The general approach of Spring BlazeDS Integration is to continue to use the standard BlazeDS XML configuration for the parts that are fairly static and more of an infrastructure concern, such as channel definitions, but to allow things that change more frequently during the development of the application, such as remoting destinations, to be configured using the familiar Spring configuration model. As such, exposing a Spring-managed bean for direct remoting from a Flex client is a simple matter of wiring up a remoting exporter bean. Examining the Spring configuration from the sample further, you will see this in action:
<!-- Implementation of ProductService using Spring's SimpleJdbcTemplate -->
<bean id="productService" class="flex.samples.product.JdbcProductService" >
<constructor-arg ref="dataSource"/>
</bean>
<!-- Expose the productService bean for BlazeDS remoting -->
<bean id="product"
class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter">
<property name="messageBroker" ref="mySpringManagedMessageBroker"/>
<property name="service" ref="productService"/>
</bean>
Here you can see a simple Spring bean productService that is being exported as a remoting destination to the Spring-managed MessageBroker. By default, the desination's serviceId will be the same as the bean name. This service can be accessed from Flex client code such as in the following MXML example from /samples/WEB-INF/flex-src/testdrive-remoteobject/src/main.mxml:
<mx:RemoteObject id="srv" destination="product"/>
<mx:DataGrid dataProvider="{srv.getProducts.lastResult}" width="100%" height="100%"/>
<mx:Button label="Get Data" click="srv.getProducts()"/>
The Spring-managed MessageBroker handles the details of invoking the getProducts method on the productService bean and the serialization back and forth between Flex's native AMF data format and Java.
The final piece in this puzzle is the configuration for actually routing the Flex AMF message requests coming into the DispatcherServlet through to the MessageBroker. This is done with a simple HandlerMapping in conjunction with the MessageBrokerHandlerAdapter definition in the Spring configuration:
<!-- Maps request paths at /messagebroker to the BlazeDS MessageBroker -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/messagebroker/*=mySpringManagedMessageBroker
</value>
</property>
</bean>
<!-- Dispatches requests mapped to a MessageBroker -->
<bean class="org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter"/>
The end result of this in conjunction with the mapping of the DispatcherServlet is that requests at the path /spring/messagebroker/* will be routed to the Spring-managed MessageBroker. Notice that the BlazeDS channel definitions in /WEB-INF/flex/services-config.xml correspond to this mapping, for example:
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
Of course, if you prefer, you can set these channels up separately in the Flex client (so that you don't have to compile the Flex source against services-config.xml), perhaps even using the Spring ActionScript community extension.
Community Feedback Wanted
With this foundation in place, we hope to see Spring BlazeDS Integration evolve into the essential component for building Spring-powered RIAs with Flex. This project was started in response to ongoing demand from the Spring community for a first-class solution for reducing the complexity of building applications with Flex with Spring, and it should continue to progress by addressing the needs of the community. The way for us to ensure this is the case is to invite you once again to try it for yourself and get involved through the forum and Jira. We welcome your feedback and look forward to working together towards a final 1.0 release.
Similar Posts
- Using Spring BlazeDS Integration 1.0
- Spring Integration 1.0.3 Samples: just add Maven
- Git Migration
- Code samples from SpringOne 'Beyond the obvious' talk
- Spring Integration 1.0.3 Samples: just add OSGi











Mark says:
Added on December 17th, 2008 at 2:44 pmThat's a great addition…will it be limited to BlazeDS or also support alternates like GraniteDS (www.graniteds.org)?
Jeremy Grelle (blog author) says:
Added on December 17th, 2008 at 2:55 pmMark,
It is specifically targeting BlazeDS as we are developing it (as well as commercial extensions for LiveCycle DS) in partnership with Adobe.
Thanks,
Jeremy
James Lorenzen says:
Added on December 17th, 2008 at 5:09 pmWhat about adding first class support in grails for future versions?
Cristian Pascu says:
Added on December 17th, 2008 at 5:26 pmIt exciting to see SpringSource take action for what community have strive hard to achieve in the past one year or two.
Server data push would be a very, very nice thing to have in this integration project. If not, maybe there will be sufficient design openness to let the community implement it, or use GraniteDS's Gravity instead. Having server push only with a subscription will be just sad, understandable from business point of view, but just sad.
Good luck with out initiative. It's most surely welcomed by the Flex excited Spring lovers.
James Law says:
Added on December 17th, 2008 at 6:36 pmThis is great news, I am excited Spring will be creating some form of flex integration. Does SS have any plans to deal with some of the serialization/dto challenges that adobe's serializer presents? For example, it is not really practical to directly return hibernate domain objects with relations, because the adobe serialization attempts to eagerly fetch all of them before moving the objects over afm. Thus to move objects back to the flash player and actionscript, we have had to create value objects.
Thanks
J
Joe Rinehart says:
Added on December 17th, 2008 at 9:22 pmThis is just excellent news. I work on a few good-sized Java/Groovy-backed Flex app that also make use of Spring JMS, so my thoughts immediately went to configuring JMS-backed realtime / push destinations for Flex. Looks like there's already a ticket for is (#FLEX-13) - if you're looking for testers / contributors, I'd be happy to help, as would a few others at my company.
Carlos Rovira says:
Added on December 18th, 2008 at 8:20 amGreat to see this project. Right now there's some good ways to integrate Spring with Flex but Spring direct support could be the response for complicated things (like the one James Law points about serialization issues). We'll follow up this project very close since it's really useful and interesting.
Thanks for start it!
Carlos Rovira
Jeremy Grelle (blog author) says:
Added on December 18th, 2008 at 10:34 amJames,
Grails does already have a plugin with functionality that is similar to that of this M1 build.
http://grails.org/Flex%2BPlugin
That said, an alternate version of the plugin that builds on Spring BlazeDS Integration makes sense as we continue adding features that go beyond remoting. We don't have any definite plans for that at the moment, but it is certainly something we will consider if there is community demand.
Thanks,
Jeremy
Andrew Powell says:
Added on December 18th, 2008 at 10:39 amI think the issues people are having with the serializer are Adobe's problems, not SpringSource's. Don't expect to see much movement on them either b/c if BlazeDS worked perfectly with Hibernate, why would you need to buy LiveCycleDS? There are ways around it like using an interceptor to create a detached object before it hits the serializer, etc.
Jeremy Grelle (blog author) says:
Added on December 18th, 2008 at 10:42 amCristian,
Server-side push is something that BlazeDS already enables, and we do have plans in the roadmap for Spring-specific integration with those capabilities utilizing Spring's JMS support. We are considering a simpler option as well that allows interaction with the BlazeDS MessageService from Spring-managed beans without the need for JMS.
Thanks,
Jeremy
Benoit Guerout says:
Added on December 18th, 2008 at 3:14 pmSpring BlazeDS Integration is the project i'm looking for since months …
Thanks
Vigil Bose says:
Added on December 22nd, 2008 at 11:17 pmThis is awesome. I have been waiting for a similar functionality that Spring BlazeDS integration provides around FLEX and Spring for quite some time since I work on a modernization project to replace PowerBuilder front end application talking to CICS/COBOL on the mainframe backend. Flex and Spring makes an ideal choice to replace the legacy PowerBuilder 4GL technology that is currently in use.
James says:
Added on December 23rd, 2008 at 5:41 pmLooks great.
Tried to run test using MyEclipse.
Deployment looks fine, flex page renders, but when pressing Get Data nothing happens. No log messages of any value. DB is started.
Any ideas?
Chris Giametta says:
Added on December 31st, 2008 at 4:42 pmI am in process of writing a book for Apress that is written around Flex and Spring integration. The book is Pro: Flex on Spring and is to be published March 2010. This project is extremely promising and I will cover it in the book as well as build several applications using this instead of SpringFactory like I have for years.
I realize this is early in release but I feel it will clean up quite a bit of difficult integration configuration from what I have worked with so far.
As far as the examples not working James, be sure to have xalan.jar in the classpath for the application. That was not found in the download.
Chris Giametta says:
Added on December 31st, 2008 at 4:46 pmMy book is to be published next March, which would be 2009. Whoops.
Anton Murauyou says:
Added on January 5th, 2009 at 2:18 amHello, guys. I've done everything exactly as you said but my Flex client application returns error saying "No destination 'my_destination' found or channel not defined (and default channel not found)". I've defined default channel, but remoting-config.xml as supposed contains no destinations.
Is that happening because of the way I build my Flex application (I do it through Flex Builder 3 and I've defined WTP features and server URL and folder)?
Mandar K says:
Added on January 6th, 2009 at 9:02 amHi Anton,
I am also facing the same issue.I have created the swf file using ant.Did you get any luck to resolve the issue?
Jeremy, I have done a simple copy-paste of all the XML files in your sample application.Still my application does not work..!
Jeremy Grelle (blog author) says:
Added on January 6th, 2009 at 9:06 amAll,
For further help in getting started, please use the project forum.
http://forum.springframework.org/forumdisplay.php?f=61
Thanks,
Jeremy
François says:
Added on January 6th, 2009 at 11:20 amHello Jeremy,
Nice to see that you springsource guys are delivering this.
I’ve also been playing around with spring/blazeds/flex lately but before you release this new library.
The result was pretty elegant as well with spring service being autowired as flex/blazeds remote service at bootstrat (we named the library flex-contrib-spring), have a look at :
* http://code.google.com/p/fna/
* http://fna.googlecode.com/svn/trunk/fna/site/flex-contrib-spring/index.html
and our archetype:
* http://fna.googlecode.com/svn/trunk/fna/site/mvn_archetypes/blazeds-autowired-spring-hibernate-archetype/index.html
let me know.
Meanwhile I'll give your stuff a try as well.
Regards !
François
matrin911 says:
Added on January 21st, 2009 at 10:00 amDoes anyone know how to implement amf-secure protocol??
rgds
martin
Eric Weimer says:
Added on January 26th, 2009 at 5:03 pm1 (Actually about 20) for Grails plugin to BlazeDS
Dirk Dinger says:
Added on January 28th, 2009 at 2:58 amAre the blazeDS and spring-flex maven artifacts available in any maven repo ?
Regards,
Dirk
Jeremy Grelle (blog author) says:
Added on January 28th, 2009 at 9:08 amYes, the artifacts are available in the SpringSource Bundle Repository.
http://www.springsource.com/repository
zhou says:
Added on February 10th, 2009 at 10:29 pmi have a question ,how to use the OpenSessionInViewFilter in the 'Spring BlazeDS Integration'. I found it that i have to use the DispatcherServlet and load the spring cfg in the DispatcherServlet ,but i can't use the ContextLoaderListener at the same time ,how can i do ,thank you
zhou says:
Added on February 10th, 2009 at 11:56 pmhow can i use OpenSessionInViewFilter here
zhou says:
Added on February 12th, 2009 at 10:33 pmno one answer me;
if i can use hibernate's lazy
Dan Mayolo says:
Added on February 17th, 2009 at 8:11 pmI would like to take a peek at AMFView and REST support. Any code/docs available for early preview?
Thanks
fake says:
Added on February 20th, 2009 at 7:33 amjust a quick note: in WEB-INF/flex/services-config.xml in the test drive project, only the "simple" AMF endpoint has the added "/spring/" you bound your mvc dispatcher to in it's path, the amf-polling and amf-secure miss this.
kuttikumar says:
Added on March 12th, 2009 at 5:00 amHi,
i have a one question ,how to implement the Producer and Consumer methodology in the 'Spring BlazeDS Integration' in DataBase value insert.
alon says:
Added on March 22nd, 2009 at 7:17 amHi,
What's the best work around for working with hibernate and using collections lazy loading?
Micheal.lee says:
Added on April 9th, 2009 at 10:11 pmi hope look at hibernate in your project!
JC says:
Added on June 4th, 2009 at 1:22 pmIs there a version of this updated for the RC? If not it would be nice (or at least note the changes). I tried it and have noticed that the package name for org.springframework.flex.messaging.MessageBrokerFactoryBean has changed to org.springframework.flex.core.MessageBrokerFactoryBean, not sure if that is the only change.