Flex – SpringFramework Integration
There is alot of talk about the difficulties in integrating Flex with Java and the SpringFramework. Primarily tis is cause by the lack of a clear example in the documentation and installation software. This post tries to rectify this by giving a example as to integrate the two technologies. What will be done:
(Feel free to skip any steps if you already have the specific software installed on your system)
1. Installation of Tomcat
2. Installation of the Flex data service express war files into Tomcat
3. Install maven 2
4. Install Eclipse 3.3
5. Creation of a simple example in Eclipse
First. The installation of Tomcat. Goto the apache tomcat site and download the latest version. (Tomcat 6.x). Follow the install instructions and within 5 minutes you should have tomcat running on your machine.
Second. Get the Flex data service express from the adobe site. Remeber that this software is licenced. (Flex data Service express). From this we only need the following war-files: (flex.war, flex-admin.war en samples.war). Now that you have the war-files, deploy them in your tomcat installation (i.e. copy them in your <installroot>/webapps directory. Tomcat should autodeploy the war files. Now TEST is flex is running by going to the following adress (http://localhost:8080/flex). here you should see a message that FDS is running on your tomcat installation. If this is not the case, check your tomcat logs files as to the cause of your problem.
Third. Install maven 2 on your system. (Maven 2 download). Follow the install instructions provided by the maven team.
Fourth. Install Eclipse. I have installed Eclipse + the WTP preconfigured. (Eclipse all in)
Now that we have the prerequisits for our sample application, the “hard” word will begin. We are going to create a FDS flex spring application from the ground up.
1. First we fire up our Eclipse workbench. Next thing we will do is to create a standard maven 2 java project in Eclipse. This would look like this:
- <flexspringintegration>
- src/main/java
- src/resources
- src/test/java
- src/main/webapp
- pom.xml
- project.properties
The pom.xml would contain nothing much more that my default dependancies (junit and log4j)
2 . In this empty default structure we are going to incorperate the flex.war content (this war-file we have deployed on our tomcat installation also). This is not very complex, but it needs to be done with care. it means that all resourcs from this war go into the WEB-INF directory of our java project. The WEB-INF directory structure should look like this:
- src/main/webapp/WEB-INF
- flex/
- hotfixes/
- jars/
- libs/
- locale/
- user_classes/
- lib/
- web.xml (the web.xml from the flex.war)
- flex/
the contents of the directories have been omitted.
3. Now we are going to insert all spring related resources including a class from another fine flex/java developer and integrate this into our java project. This class is a factory that is the magic in our flex spring integration. Here are the files I added and the correct location
- /src/main/java/nl/wowww/flex/spring/factory/SpringFactory.java
- /src/main/webapp/WEB-INF/applicationContext.xml
4. In order for flex to be able to make use of the provided SpringFactory class, we must define this in the services-config.xml file. This file is located in our project in the location /src/main/webapp/WEB-INF/flex directory. Add the following piece of code to it:
<!– Spring factory registration –>
<factories>
<factory id=”spring” class=”nl.wowww.flex.spring.factory.SpringFactory”/>
</factories>
This small configuration maked the factory we provided know to flex.
5. Now we add some exmaple beans and mxml file for us to play with in our example. These are the files (Mortgage.java, RateFinder.java, SimpleRateFinder.java and MortgageCalc.mxml). The mxml must be in the /src/main/webapp directory and the others in the src/main/java…. directory conform their package structure.
6. Now we add the beans in our spring configuration file:
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”>
<beans>
<bean id=”rateFinderBean” class=”nl.wowww.flex.spring.mortage.SimpleRateFinder”/>
<bean id=”mortgageBean” class=”nl.wowww.flex.spring.mortage.Mortgage”>
<property name=”rateFinder” ref=”rateFinderBean”/>
</bean>
</beans>
7. Now we must add some config to the file src/main/WEB-INF/flex/remoting-config.xml:
<destination id=”mortgageService”>
<properties>
<factory>spring</factory>
<source>mortgageBean</source>
</properties>
</destination>
This config will enable flex to do a remoteObject call to the spring beans, while spring keeps managing the beans.
8. final steps are to add the libraries in our spring project. I add those directly from my maven 2 repository through varaible reference. I leave it up to you to add the following libs to the path in your eclipse project: spring.jar, servlet-api-2.4.jar, flex-messaging.jar and flex-messaging-common.jar (the last two files you can again find in your flex.war).
9. Now your project should compile in eclipse, but we are not quite ready yet. Maven compile does not work.To fix this we should add all dependacies into our po.xml. Missing libraries (flex and spring) should be installed in our local repository. To install the issue the following command. Alter the location of your jar files accoordingly.
mvn install:install-file -DgroupId=springframework -DartifactId=spring -Dversion=2.0.6 -Dpackaging=jar -Dfile=spring.jar)
mvn install:install-file -DgroupId=flex -DartifactId=flex-messaging-common -Dversion=2.5.166921 -Dpackaging=jar -Dfile=flex-messaging-common.jar
mvn install:install-file -DgroupId=flex -DartifactId=flex-messaging -Dversion=2.5.166921 -Dpackaging=jar -Dfile=flex-messaging.jar
10. now we can create our own war file for deployment. mvn compile, mvn war:war and your own war file should be present. Deploy the war into your tomcat installation and you should have a working flex-spring integration example using remoteObject technology.
Regards.
wowww.nl
Gepost in categorie: TechTalk
Tweet
Hey,
Any thoughts on Acegi security framework integration?
Thanks
31 juli 2007 om 13:13Matt
Matt,
I think Acegi will integrate as you would using a regular Spring application. Only the front-end is a bit different (as in Flex), but the rest is standard Java.
But i have never used Acegi, so you have to keep this in mind.
Regards,
Marc
13 augustus 2007 om 02:04Hi, Mark,
I downloaded Maven plugin for Eclipse and attempted to build this project based on the steps above. If all these pieces are not already in place for a developer, you can most likely assume that they are ***new*** to everything you are writing about. Translation: you kinda need to be very specific about the steps (commands to run, expected results, snapshots of windows, locations of files).
The reason I thought I might try this example is because I’m using Hibernate 3 and having a very basic problem integrating my actionscript class files into my webapp. When I compile it’s not finding the actionscript files. I thought Maven might help with the dependencies but I’m not sure whether it will or not.
28 augustus 2007 om 09:39Hi Laurie,
You are right in your assumption that I have written this post with a moderately experienced developer in mind. That is why I just summed up the components you need and did not give any detailed steps in how to install/use them. But thank you for the advice and I shall try to adhere to it in my future posts.
In the meantime. I can always give tips/help if you can not get this sample project to work.
regards,
29 augustus 2007 om 02:59just FYI
You don’t actually need to manually install the spring.jar in your local maven repository
just replace
springframework
by
org.springframework
in your pom.xml
and you’ll be fine.
Cheers ! and thanks for this article !
7 september 2007 om 06:56Hi, again, thanks for your response. I stumbled on this site (again) and saw it (two months later). I should have at least thanked you for your post because not a lot of people take the time to help the noobies. So — it is appreciated.
Laurie Hall
26 oktober 2007 om 12:23Hi,
Have come to this article as I am looking at porting a ajax based web app to a flex front end. The service tier is exposed using spring http invoker – I assume that the flex gui can comsume these services?
11 maart 2008 om 04:23Also this app is very data centric (there is alot of it) – I am worried about performace in flex gui – most of the samples are small apps with little real data, any thoughts on this?
Terry,
Yes I believe you can connect to this service. As long as you can output and input xml there should be no problem.
In order to answer your question about performance, I should have more information. Is there a need to retrieve lots of data at once for analysis or do you have a crud application with lots of data in the backend??
CRUD applications dont need much data in the gui and therefore are not that perfomance sensitive. If you are doing analysis on bulk data in the frond end, then there can be a problem. But I would reccomend to push such functionality to the server side if possible.
Kind regards,
15 maart 2008 om 05:53Marc
Great example.
What would you do in the case of the following:
1. Not being a Java developer
2. Having access to the source code of an entire CMS system (Alfresco)
3. Wanting to integrate Alfresco with BlazeDS by just exposing the existing beans in the deployed server
It seems that to integrate BlazeDS into something like Alfresco would be a monster undertaking because you’d have to modify the Java classes or do a ton of configuration work.
I found that you guys have some experience in BlazeDS and Alfresco… do you or anyone you work with have any suggestions/tips on how a Flex developer might tinker with this type of thing?
3 april 2008 om 09:42Jon,
What you are suggesting is indeed a monster undertaking.
If you expose the beans to BlazeDS then you stil have to put the faces logic somewhere.
I would probably hook into the jsr repository functions and build my own interface. Flex is all about cool looking interfaces and a better use then jsf. Do not try to mirror the jsf screens. That way you will not benefit from Flex.
Your work will be porting logic, rather than screens. This will cost you the most time.
kind regards,
Marc
29 april 2008 om 08:36I don’t see anywhere on the flex data service express to download the wars. All it has is the mondo, 424MB full flex builder 3 executable! I have BEA Workshop and already have the flex builder eclipse plug in…I dont want all this crap. How do I get the files you talk about? They are not in my current flex install (part of BEA Workshop).
20 mei 2008 om 13:27Thx,
Mike
Hi,
I’m trying to develop application using Flex & Spring. Also I’m using Cairngorm framework. Problem I’m facing is with defining Transaction point.
I have Service which invokes Dao. I want to start transaction at service. This is the way I’m trying to configure transaction:
PROPAGATION_REQUIRED
I’m able to start transaction through JUnit. But when I try to invoke service from UI, I’m getting error.
Can you please help me?
Regards,
2 juni 2009 om 05:00Himanshu Rathore
I have executed the sample code
24 oktober 2009 om 07:54but did not get swf file for the flex code pls help me
can you specify what you did and what you ae missing
4 november 2009 om 10:10Hi Mark,
I am unable to find the Zip code file as mentioned in the link above in the tutorial.
404-rosource not found error.
Can u please provide me….
contacttosoumya@gmail.com
Thanks in advance.
27 december 2009 om 03:13Soumya
comment5, Laigle noir mp3, [url="http://712.jiur895.tk/"]Laigle noir mp3[/url], rifzpk, Dbz yaoi fanfiction, [url="http://838.xq4hu8n.tk/"]Dbz yaoi fanfiction[/url], =]], Div overlay myspace layouts, [url="http://723.ubd2z9r.tk/"]Div overlay myspace layouts[/url], 74724, Remove etching from glass, [url="http://275.2k03i.2y.net/"]Remove etching from glass[/url],
D, Sturgis girl pictures, [url="http://388.5ihmu.2y.net/"]Sturgis girl pictures[/url],
((, Model haley campbell, [url="http://438.onmxg.2y.net/"]Model haley campbell[/url], 169937, Starwood hotels com, [url="http://235.58mr8.2y.net/"]Starwood hotels com[/url], zuy, Herbal aria giovanni movies, [url="http://698.4pb3f6j.tk/"]Herbal aria giovanni movies[/url], 885608, Tgp femdom, [url="http://576.iwc44oq.tk/"]Tgp femdom[/url], >:DDD, Pascua lama george bush, [url="http://184.oe9ak6u.tk/"]Pascua lama george bush[/url], %P,
18 oktober 2010 om 19:17Having already mastered the artistry of menswear for decline, it’s occasion to upon the most swell parenthetically a via to pack off in requital for when temps become due south. Fortunately, you won’t require to look much farther than your closet to wrap yourself in with it goodness.It’s like they were saying, we recollect you make to have your Christian Louboutin shoes a number of different ways, we recognize these be experiencing to useful to a purpose in your survival for the weekend, when you’re with your kids, when you’re at work, when you’re effective out at gloaming,So here’s a approach you can get the most entirely of something that you from in your closet. And if you look at it like that, it’s like, ‘wow, this is gonna breath new lifetime into how I attrition everything.
20 oktober 2010 om 19:01There are no rules suitable now in fashion. You can be glamorous morning, high noon and night. You can mix prints. You can step sequins in the sun. The alone supervision is to take a shot to look your foremost and to comprise make sport and feel honourableness about what Christian Louboutin Platforms you’re wearing.
[...] http://www.wowww.nl/wordpress/?p=58 [...]
7 mei 2012 om 10:05