Thursday, December 4, 2008

Integrating Spring with Flex on TOMCAT

This is a sequel to my post on getting up and running with blazeds/flex/tomcat on eclipse. This little post is going to explain how to integrate your ultra cool flex front end with the spring framework.Checkout if you are not familiar with spring or Dependency injection.

Alright.Here are the steps.

1.Setup your blazeds server and client as mentioned in the previous blog post
2.Download the spring framework from Extract and move the neccessary jars into WEB-INF/lib folder of your server application.
3. Add the spring context param and listener to your web.xml file:



4.Download the flex spring factory from COmpile it and have the class file inside your WEB-INF/classes folder .

5. Add the following configuration to your WEB-INF/flex/services-config.xml file:

<factory id="spring" class="flex.samples.factories.SpringFactory" />

6.Define your components in spring's XML file. Given the above spring
configuration, they would be placed in WEB-INF/applicationContext.xml. This
file can contain components which are intended to be exposed to flex clients as
remote objects as well as classes to be used as Flex Data Management Services
(FDMS) assembler implementations using the Java adapter.

7.To be constructed by Spring, your component should have a zero argument constructor so
Spring can construct an instance. Your applicationContext.xml file might look like:

<?xml version="1.0" encoding="UTF-8"?>

<bean name="weatherBean" class="" singleton="true"/>

<bean name="myAssembler" class="dev.assemblers.MyAssembler" singleton="true"/>

8.Add your flex destination configuration for the components you want to expose to
flex clients. Since these components use the spring factory we define, we add the
additional tag <factory>spring</factory> and the <source> attribute is used to refer
to the spring component's bean name, not the class name as with the default factory.

For Remote object destinations you place your destinations inside of the
<service> tag which refers to the,
(by convention this may be in WEB-INF/flex/remoting-config.xml). For example, your
remote destination configuration might look like:

<destination id="WeatherService">

9.Use a simple client and set your remote object destination to the one you created on your remoting-config.xml

10.Restart your server.Test. Off you go!!

Bookmark and Share

No comments: