Flex 4, Java, Spring, and Hibernate in Flash Builder 4

UPDATE 1: Flash Builder 4, BlazeDS 4, and Spring 1.0.3 have all been release so you no longer have to use beta or nightly builds of these products. Use the production versions!

UPDATE 2: A Refcard on Integrating Spring 3 and Flex 4, which I co-authored, is now available! It provides a step-by-step tutorial for setting up everything I show in the video below.

Last week I posted a screencast that walks through the basics of connecting a Flex 4 application to a Java / Spring back-end with the new Data Wizards in Flash Builder 4. Here is a new video that extends beyond just simple RPC method calls and adds Hibernate for persistence. Let me know what you think.


(Open full-size video in a new window)

This entry was posted in Flex, Hibernate, Java, Spring. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • http://lifuming.com Enjoy

    hi!! can you please post a screen-cast for connecting FB4 with Granite-DS 2.2 from scratch with GDS flex plugin for grails because lots of people have not been able to link GD with fB4 and grails please if you can do it… i really need it.

  • Dilawar

    Thanx a lot…

  • http://www.to-fuse.ch Rico Leuthold

    Hi James,

    I was really impressed by the java remoting stuff you demonstrate in the screencast and gave it a try. Connecting the whole thing to MySQL was easy. But I’m really annoyed by this bug https://bugs.adobe.com/jira/browse/FB-26262

    The destination “[dest]” used by service “[service]” was not found in the services configuration file. Update the config file and refresh the service in the Data/Services view.

    Do you have any Idea for a workaround? In my opinion it’s a pity that adobe deferred this bug.

    best.rico

    • http://www.jamesward.com James Ward

      Hi Rico,

      Unfortunately I don’t know of a way to work around that bug. Sorry!

      -James

  • Prakash

    Dear James

    This tutorial is excellent . But i am getting Java.lang.NullPointerException? Can you please suggest what is wrong ?

    java.lang.NullPointerException
    at Blah.Foo.addBar(Foo.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdap
    ter.java:421)
    at flex.messaging.services.RemotingService.serviceMessage(RemotingServic
    e.java:183)
    at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java
    :1406)
    at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndp

    • http://www.jamesward.com James Ward

      Maybe the bar name was null? What are the contents of your addBar method?

  • Prakash

    Dear James
    I could solve the error. every thing is fine now.
    Can you please send some examples for one to many relationship objects to save and get from database please ?

    • http://www.jamesward.com James Ward

      I believe there is a sample with that in the Spring Flex Testdrive (part of the Spring BlazeDS download).

  • ashish patel

    Dear John,
    How to achieve below requirement using BlazeDS ?

    Requirement :
    I have one small web application developed using spring 3.0 and hibernet.
    I have one screen for displaying customer. screen having add/edit and delete customer button.
    I have open 3 instance of browser.
    one first browser , i have added customer .. after clicking on add button , on grid customer will display.
    at the same time other two browser , same custome should be displayed without refresh the page.
    How can i achive this ?

    Looking forward to your prompt response.

    • http://www.jamesward.com James Ward

      Yes. You can do that with Spring, Hibernate, and Flex.

      • ashish patel

        Dear Jamesh,

        Thanks for promt response.
        I would really appreciate if you give some hints to achieve the my requirements.
        Small examples are really appreciated.

        Regards,
        Ashish Patel

  • Rupen

    Hello James,

    Thanx for the amazing tutorial .. I was doing the way u mentioned since some time .. But now started using cairngorm 3 framework , and facing problem to connect to the spring service from the cairngorm delegate .. Can you please help me in telling the way to call this Spring service from cairngorm …

    Thanx in Advance,
    Rupen

    • http://www.jamesward.com James Ward

      That should just work. What is the problem you are having?

  • Tee

    Thanks james . i follow your tutorial and create a similiar test . I face this problem . My template value become null when flex’s remote object invoke getBar() method . Then i debug futher , my setSessionFactory get invoke when i start tomcat . Meaning autowired is working without problem. But why when flex invoke getBar method , value of template become null.

    Thanks

    • http://www.jamesward.com James Ward

      Can you email me the spring config and Java code that you are using? jaward at adobe dot com

  • Rupen

    Hello James,

    The problem I am facing is .. I am getting the error
    Detected duplicate HTTP-based FlexSessions .. I tried using the session created by the webserver JSESSIONID still i am unable to surpass this problem …

    • http://www.jamesward.com James Ward

      Make sure you have this line in your web.xml file:

      <listener>
                      <listener-class>flex.messaging.HttpFlexSession</listener-class>
      </listener>
      • Rupen

        I did that James .. But when i deploy flex server on Jboss on initialisation it was creating a session and while am trying to create a new connection its giving that error ..

        I am having 2 apps accessing the same server and this server is being popped some times .. not every time .. but some times .. Can this be due to 2 apps accessing same server at same time ???

        • http://www.jamesward.com James Ward

          It should work fine with 2 apps accessing the same server. Are you using the latest version of BlazeDS?

          • Rupen

            Yep am using the latest version of blazeDS .. Flex 4 + eclipse helios + blazeDS(latest version) …

          • http://www.jamesward.com James Ward
          • Rupen

            Thanx a Lot Sir,

            U are of great help .. This question is out of topic but is there any book or something or some online link where i can get all tutorials of urs ?? ..

            And right now am facing a problem .. I changed some configurations of eclipse and right now while am adding the service the service action script shows ..

            _serviceControl.operations = operations;
            _serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
            destination = “getDashBoardData”;

            It was giving MessagingError : Destination “getDashBoardData” not found ..

            I modified that to this and it started working

            _serviceControl.operations = operations;
            _serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
            _serviceControl.endpoint = “http://localhost:8091//messagebroker/amf”;
            destination = “getDashBoardData”;

            But initially when i was doing i was not forced to do this manually .. Am I doing something wrong ????

          • http://www.jamesward.com James Ward

            If you specify the server configuration in the Flash Builder project then you don’t need the endpoint information because it copies it into the application for you. However if you don’t specify the server configuration then you need to set the endpoint.

      • Novice

        Hi James ,

        While am using this example I am getting the error

        log4j:WARN No appenders could be found for logger (org.springframework.web.servlet.DispatcherServlet).
        log4j:WARN Please initialize the log4j system properly

        Can you help m to sort this …

        • Novice

          The entire Tomcat Start log is like

          Apr 11, 2011 4:16:08 PM org.apache.catalina.core.AprLifecycleListener init
          INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.6.0_03\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Java\jre1.6.0_03\bin;
          Apr 11, 2011 4:16:08 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
          WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:DeviceAccUpdater’ did not find a matching property.
          Apr 11, 2011 4:16:08 PM org.apache.coyote.http11.Http11Protocol init
          INFO: Initializing Coyote HTTP/1.1 on http-8091
          Apr 11, 2011 4:16:08 PM org.apache.catalina.startup.Catalina load
          INFO: Initialization processed in 320 ms
          Apr 11, 2011 4:16:08 PM org.apache.catalina.core.StandardService start
          INFO: Starting service Catalina
          Apr 11, 2011 4:16:08 PM org.apache.catalina.core.StandardEngine start
          INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
          log4j:WARN No appenders could be found for logger (org.springframework.web.servlet.DispatcherServlet).
          log4j:WARN Please initialize the log4j system properly.
          Apr 11, 2011 4:16:09 PM org.apache.catalina.core.ApplicationContext log
          INFO: Initializing Spring FrameworkServlet ‘dispatcherServlet’
          [BlazeDS]No login command was found for ‘Apache Tomcat/6.0.29′. Please ensure that the login-command tag has the correct server attribute value, or use ‘all’ to use the login command regardless of the server.
          [BlazeDS]Endpoint ‘my-amf’ created with security: None
          at URL: http://{server.name}:{server.port}/{context.root}/messagebroker/amf
          Apr 11, 2011 4:16:11 PM org.apache.coyote.http11.Http11Protocol start
          INFO: Starting Coyote HTTP/1.1 on http-8091
          Apr 11, 2011 4:16:11 PM org.apache.jk.common.ChannelSocket init
          INFO: JK: ajp13 listening on /0.0.0.0:8010
          Apr 11, 2011 4:16:11 PM org.apache.jk.server.JkMain start
          INFO: Jk running ID=0 time=0/16 config=null
          Apr 11, 2011 4:16:11 PM org.apache.catalina.startup.Catalina start
          INFO: Server startup in 3356 ms

          Here am not able to get ‘foo’ started thing .. Plzzz help

        • http://www.jamesward.com James Ward

          The log4j warning won’t prevent the application from running and the server started up correctly. So the problem must be due to your Spring configuration not picking up the bean.

  • Chathura

    I have small issue in connect BlazeDs data connection wizard. it gives error when try to connect RDS server. how can I enable RDS feature in tomcat 6. Its necessary to do any modification to tomcat? or need to install any third party application?
    pls help.

    regards,
    Chathura

  • Shawn

    Hi James,

    Hi James,
    I’ve been building Flex/Coldfusion apps for about 5 years and just for curiosity sake wanted to look at a Flex/Java project and came across this.

    Instead of seeing Flex with Java backend, I see Flex with Java – Spring – Hibernate – Tomcat backend.
    I understand that Hibernate is for persistence, but are all of those necessary for a Flex/Java app ?

    I’m just curious since Coldfusion 9 comes with ORM so you don’t need anything other than Flex/Coldfusion for the same thing…. why would someone want to involved with integrating so many different server applications for a backend vs having just one ? Even if you installed CF on a J2EE server, it would still be 2 on the back instead of 4. Like I said, I’m just curious. TIA

    • http://www.jamesward.com James Ward

      I’m really not familiar with CF. Sorry.

      • Shawn

        Oh ok. Coldfusion is Adobe’s back-end application server that seamlessly integrates with their Flex front-end. I wanted to learn how to build a Flex/Java app just because everyone always tells me that my CF code looks just like Java, but I didn’t know that it required all those other things.

  • michael

    Hello James,

    Thank you for your amazing tutorial. It was very important tutorial for me, but I have some problems in my project.
    Could you please send me some source files such as web.xml,dispatcherSevlet-server.xml, and services-config.xml.

  • yweeeen

    hi, just wondering, Is Flex and Java integeration only for web application? or applications that requires a server?

    What if just a desktop application which does not requires server? does it work?

  • Gustavo

    Hi james i’m from brazil and would like to download from this project…could you provide it in soon?

    thanks