Using Flex with Spring

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.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • StumbleUpon
  • Twitter
This entry was posted in Flex, Java, Spring. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

21 Comments

  1. kazi
    Posted October 22, 2006 at 5:10 pm | Permalink

    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. Posted November 14, 2006 at 2:56 pm | Permalink

    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. Posted November 14, 2006 at 3:04 pm | Permalink

    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. Posted November 15, 2006 at 9:49 am | Permalink

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

  5. may
    Posted November 20, 2006 at 10:45 am | Permalink

    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
    Posted January 9, 2007 at 10:28 pm | Permalink

    Christophe,

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

    :)

    GP

  7. Matt Madhavan
    Posted August 7, 2007 at 8:44 am | Permalink

    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

  8. Posted May 3, 2008 at 8:53 pm | Permalink

    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

  9. Posted August 22, 2008 at 5:45 pm | Permalink

    ThankS.

  10. Posted August 22, 2008 at 5:46 pm | Permalink

    thankS a lot

  11. Posted August 22, 2008 at 5:47 pm | Permalink

    thanks good… ;)

  12. Posted August 22, 2008 at 6:00 pm | Permalink

    thanks good … ;)

  13. Posted August 28, 2008 at 10:41 pm | Permalink

    thanks you very good

  14. Posted August 28, 2008 at 10:42 pm | Permalink

    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.

  15. Posted August 28, 2008 at 10:43 pm | Permalink

    very great thanks you

  16. Posted November 20, 2008 at 9:15 pm | Permalink

    thanks good … ;)

  17. Sanjay
    Posted February 19, 2009 at 2:51 am | Permalink

    Pls. provide previous contents for “Using Flex with Spring” link (http://coenraets.org/flex-spring)

  18. Posted February 23, 2009 at 4:14 pm | Permalink

    Looks like people are pretty much begging you for Acegi security integration. Any ideas

  19. Posted March 17, 2009 at 4:53 pm | Permalink

    very great thanks you

  20. Posted June 13, 2010 at 9:17 am | Permalink

    Thanks your post admin.

  21. Posted August 8, 2010 at 7:52 am | Permalink

    very great thanks you

3 Trackbacks

  1. [...] 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. [...]

  2. By It’s all about RIA on October 14, 2008 at 1:25 am

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

  3. By It’s all about RIA on October 14, 2008 at 1:26 am

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>