Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Integrating Spring and Flex

0 (0 Likes / 0 Dislikes)
[ADOBE DEVELOPER CONNECTION] Hello, my name is Christophe Coenraets and I'm a Technical Evangelist with Adobe. Today I want to talk to you about Spring and Flex integration. You can find more information about the project if you go to the SpringSource website, and there is a homepage for the project at springsource.org/springflex. As part of the integration, we also built what we call a Test Drive, to get you started as fast as possible building Flex applications with the Spring framework. You can find the Test Drive on the adobe.com website and I also maintain updates of the Test Drive on my own blog. So when you start a Test Drive, the Test Drive is essentially a version of Tomcat with the Spring BlazeDS integration project built in and ready to use. You will get this home page, and essentially, the Test Drive is a collection of samples covering all the features of the Spring BlazeDS integration project. So what I will do today with you is take you through a couple of examples, just to give you an idea of what it's like to build Flex applications with the Spring framework. So the first application that we will look at is an application called InSync and InSync is a simple contact management application that allows you to look at your contacts and manage them in the database. So to look at the code, we'll switch to Flash Builder here, and this is the starting point of the application so as you can see, just a few lines of code, and if you have worked with Flex before, you will recognize the remote object component here that simply allows you to remotely invoke methods of your Java components deployed in your application server. And from the client-side point of view, there is really no difference between developing against a traditional Java backend and then developing against a Spring backend, so what we see here is that the remote object is pointing to a destination called Contact Service. So I will show you the backend of the application now and see how that remote destination is configured on the server-side. So if we look at the web.xml for your web application, you will see a slight difference compared to an application configured for traditional BlazeDS. So in this case, BlazeDS is not really in charge of instantiating your remote components. Because if you use Spring, the whole point is to let Spring instantiate these objects to do dependency injection and outer configurations. So if you look at web.xml, you will see that the message broker servelet is not managed-- it's not declared here by BlazeDS--but in fact, we let the Spring framework instantiate the message broker. And then it's gonna be business as usual for your Spring Bean, so the components--the server-side components that you want to access from a Flex backend. So if I look at the traditional Spring configuration file here, you'll see that I have a number of Beans, product service here for a contact service that I want to access from the client side. And contact service, as you'll remember, is the destination that I was pointing to from my client application. So this is nothing new. If you use Spring, you would configure your Spring object that way. There is one additional thing that you need to do, and that I will show you here. You actually need to expose this Bean--this Spring component-- as a remoting destination. And the only thing that it does--it simply allows a Flex client to actually access that component. You don't necessarily want to expose all your components to the client. So let me show you very quickly the Java component that we're pointing to-- it's called ContactDAO.java here, and as you can see, it's a traditional Java component. We do some basic JDBC here using some of the Spring abstractions, so for instance, you have a getAll method, getContactBy Id, getContactByName, and that is exactly the method that we will invoke from the client side. So if I go back to the Flex application now, you will see that indeed I'm pointing to that contact service destination and when the user is going to click that Search button, it will allow the user to type in a few characters and then we will invoke that findByName method that was defined at the server side, passing an argument of the characters that the user typed in the user interface there. So let me actually run this application, and search, for instance, for all the employees, or all the contacts with an "e" in their name, and as you can see, the results that come back from that Spring component that was instantiated by the Spring framework. So that's the first type of configuration if you want, and in this case, we used what is known in the Spring world as the XML configuration. But more recently, people started to use a different type of configuration that was done through Java Annotations, and this type of configuration is also supported by the Spring BlazeDS integration project. So let me show you another example of an application that uses that style of configuration. So the application here is a company manager type of application, essentially the exact same type of application. And as you can see, I also have a remote object that's configured to point to a destination called Company Service. Now, if I go back to my Spring configuration file in XML, you will see that there is no Company Service configured here, and that is simply because that component is actually configured using Annotations-- using Java Annotations--so if I open my object Company.DAO.java here, you will see that class with a few Annotations. Like, for instance, @Service, company service--simply declaring the component as a Spring object--a service--and then, remember in the XML configuration I had to expose the destination. You do the same thing here using @RemotingDestination. And then you do the dependency injection again, using Annotations. You can also fine-tune the methods that you want to make available to the client application with @RemotingInclude and @RemotingExclude, so for instance if there was some functions or methods in that class that you don't want to expose to the client, you would Annotate it with @RemotingExlude. And for the rest, it's exactly the same thing--it works the exact same way. The only difference is really the way these beans are being configured, so if I run the application now, and I search for companies with an "e" in their name, you see the list of companies coming back from that Spring Bean. So this was just a quick overview of the Spring BlazeDS Integration project that allows you to very easily build Flex applications that use the Spring framework. Again, if you want additional information, please visit the Project Homepage at springsource.org/spring-flex. Thank you. [ADOBE DEVELOPER CONNECTION]

Video Details

Duration: 8 minutes and 22 seconds
Country:
Language: English
License: All rights reserved
Genre: None
Views: 145
Posted by: adobetv on Oct 21, 2010

Adobe Technical Evangelist Christophe Coenraets walks you through building Flex applications with the Spring framework, and showcases the Spring BlazeDS configuration as well.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.