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:
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:
- web.xml (the web.xml from the flex.war)
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
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 –>
<factory id=”spring” class=”nl.wowww.flex.spring.factory.SpringFactory”/>
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”>
<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”/>
7. Now we must add some config to the file src/main/WEB-INF/flex/remoting-config.xml:
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.
Gepost in categorie: TechTalkTweet