Using Flex with Spring

Many people in the Java community have recently been asking how to use Flex with the Spring framework, and more specifically, how to remotely invoke Spring beans methods from Flex applications.

Spring is one of the most popular Java frameworks. It is based on a lightweight component container that implements the Inversion of Control (IoC) pattern. Using an IoC container, components don’t instantiate or even look up their dependencies (the objects they work with). The container is responsible for injecting those dependencies when it creates the components (hence the term “Dependency Injection” also used to describe this pattern). The result is looser coupling between components. The Spring IoC container has proven to be a solid foundation for building robust enterprise applications.

The Flex and Spring integration process is actually very straightforward. Based on the interest in combining these technologies, I wrote a document providing background information, configuration information, and three examples with source code.

You can read the “Using Flex with Spring” document here.

UPDATE (1/12/2007): I put together a Tomcat-based Test Drive Server that includes these samples running out-of-the box. Read this post for more info.

Comments

19 Responses to “Using Flex with Spring”

  1. kazi on October 22nd, 2006 5:10 pm

    Hello Christophe. Please help…….. I have a ViewStack in my main application ID MyViewStack. The second Child of MyViewStack is a canvas
    which also has a ViewStack ID ChildViewStack. now my question is how do I address the second child of ChildViewStack?

    I tried this but did not work

    mx.core.Application.application.MyViewStack=1.ChildViewStack=1;

    Any help will be highly appreciated.

  2. Fuad Kamal on November 14th, 2006 2:56 pm

    Christophe, thanks for the article, I’ve been searching for anything explaining how to integrate Java w/Flex and thus far nothing else has come close to the usefulness of your article. I’m porting a Flex 1.5 app to Flex 2, the back-end uses Spring, Hibernate, and Tomcat. It has been a massive pain, perhaps because I never worked in 1.5 prior to this nor do I consider myself a Java developer, and the Adobe docs seem to lack depth in many aspects…

    My question is, can you shed more light (or point to a good reference) on the tags you modified the web.xml file with, specifically the tag? The web.xml tag in our app defined ContextLoaderServlet using a servlet tag while in your article you used a listener tag:

    context
    org.springframework.web.context.ContextLoaderServlet

    1

    vs.

    org.springframework.web.context.ContextLoaderListener

    What’s the difference? The two seem to be mutually exclusive, as having both throws an error that it’s defined twice.

    In my remoting-config.xml I define three destinations corresponding to three Java classes the application uses with remoting. Prior to reading your article I had defined them like this:

    ces-web.dispatch.com.ecarey.ces.service.trip.TripServiceDelegate
    request

    after reading your article I thought perhaps they should look more like this:

    spring TripServiceDelegate
    request

    Given, ofcourse, that I registered the factory as per your article. Any thoughts? Either way I can’t get the app to run under FDS2 yet; it throws a fatal exception from FlexSwfServlet saying ‘invalid configuration’…

    Thanks.

  3. Fuad Kamal on November 14th, 2006 3:04 pm

    sorry, looks like all the tags got screwed up in my posting (interpreted, I guess). here is the source re-pasted minus the brackets, hope its not too confusing (I suppose I could try it within a CDATA tag but I don’t want to keep posting the same comment to your blog):

    Christophe, thanks for the article, I’ve been searching for anything explaining how to integrate Java w/Flex and thus far nothing else has come close to the usefulness of your article. I’m porting a Flex 1.5 app to Flex 2, the back-end uses Spring, Hibernate, and Tomcat. It has been a massive pain, perhaps because I never worked in 1.5 prior to this nor do I consider myself a Java developer, and the Adobe docs seem to lack depth in many aspects…

    My question is, can you shed more light (or point to a good reference) on the tags you modified the web.xml file with, specifically the tag? The web.xml tag in our app defined ContextLoaderServlet using a servlet tag while in your article you used a listener tag:

    servlet
    servlet-name context servlet-name
    servlet-class org.springframework.web.context.ContextLoaderServlet
    servlet-class
    load-on-startup 1 load-on-startup
    servlet

    vs.

    listener

    listener-class
    org.springframework.web.context.ContextLoaderListener
    listener-class
    listener

    What’s the difference? The two seem to be mutually exclusive, as having both throws an error that it’s defined twice.

    In my remoting-config.xml I define three destinations corresponding to three Java classes the application uses with remoting. Prior to reading your article I had defined them like this:

    destination id=”tripServiceDelegate” adapter=”java-object”>
    properties>
    source>ces-web.dispatch.com.ecarey.ces.service.trip.TripServiceDelegate
    /source>
    scope>
    request
    /scope>
    properties>
    destination>

    after reading your article I thought perhaps they should look more like this:

    destination id=”tripServiceDelegate”>
    properties>
    factory>spring source>TripServiceDelegate
    /source>
    scope>request
    /scope>
    /properties
    /destination

    Given, ofcourse, that I registered the factory as per your article. Any thoughts? Either way I can’t get the app to run under FDS2 yet; it throws a fatal exception from FlexSwfServlet saying ‘invalid configuration’…

    Thanks.

  4. Fuad Kamal on November 15th, 2006 9:49 am

    When using Flex with Spring as described in your article, can Flex handle run-time exceptions thrown by the Spring beans?

  5. may on November 20th, 2006 10:45 am

    I am throwing an exception from my spring service and trying to handle it in the fault handler in flex. But for some reason the exception is not propogating to flex. Any suggestions?

  6. Grayson Pierce on January 9th, 2007 10:28 pm

    Christophe,

    Now let’s see an example of using Flex with acegi

    :)

    GP

  7. Ezmo Developer Blog » Using Flex Data Services with Spring and Hibernate on July 18th, 2007 4:43 am

    [...] 3. I then learned about integrating FDS with Spring, exemplified in Christophe Coenraets blog. The next step was to combine what I had learned from the Hibernate- and the Spring examples. [...]

  8. Matt Madhavan on August 7th, 2007 8:44 am

    Hi Cristophe,
    Looks like people are pretty much begging you for Acegi security integration. Any ideas. It will be great if you give some tips on this.

    Thanks
    Matt

  9. Ek5 on May 3rd, 2008 8:53 pm

    I am throwing an exception from my spring service and trying to handle it in the fault handler in flex. But for some reason the exception is not propogating to flex. Any suggestions?
    thank you

  10. sohbet on August 22nd, 2008 5:45 pm

    ThankS.

  11. chat on August 22nd, 2008 5:46 pm

    thankS a lot

  12. çet on August 22nd, 2008 5:47 pm

    thanks good… ;)

  13. çet on August 22nd, 2008 6:00 pm

    thanks good … ;)

  14. chat on August 28th, 2008 10:41 pm

    thanks you very good

  15. mirc on August 28th, 2008 10:42 pm

    Looks like people are pretty much begging you for Acegi security integration. Any ideas. It will be great if you give some tips on this.

  16. webmaster on August 28th, 2008 10:43 pm

    very great thanks you

  17. It’s all about RIA on October 14th, 2008 1:25 am

    [...] Using Flex with Spring [...]

  18. It’s all about RIA on October 14th, 2008 1:26 am

    [...] Comment! Using Flex with Spring [...]

  19. lapto battery on November 20th, 2008 9:15 pm

    thanks good … ;)

Leave a Reply