Original article: http://www.nomanland.net/2010/05/21/flex-series-guide-integration2/
What is spring blazeds integration?
Spring blazeds integration is springsource
Is used to integrate Spring and blazeds.
Why do we need spring blazeds integration?
Just as "flex4
Series 6
"Introduction: Spring and
Blazeds. However, this integration method is not natural and requires an additional configuration file blazeds, spring blazeds Integration
This situation will be improved.
Software environment required for spring blazeds integration:
- Java 5 or higher
- Spring 2.5.6 or higher
- Blazeds 3.2 or higher
Spring blazeds integration features
- Messagebroker (Core Component of blazeds) is configured as a bean managed by spring.
- HTTP messages sent by the flex client are routed to messagebroker through spring's dispatcherservlet
- Remote objects uses spring's annonation method to scan and host in spring
- Open the RDS server. To facilitate the use of fb4 (data/service) function menus
Note:
- Download Spring framework (the latest version of spring-framework 3.0.2
), Decompress the backup
- Download Spring framework dependencies (the latest version of spring-framework 3.0.2 dependencies in the draft
), Decompress the backup
- Download spring blazeds integration (the latest version of spring-Flex 1.5
), Decompress the backup
Step 1: prepare the required jar package
Copy the following three jar packages to the Lib of the sampleapp project.
- Spring framework
Org. springframework. aop-3.0.2.RELEASE.jar
Org. springframework. asm-3.0.2.RELEASE.jar
Org. springframework. beans-3.0.2.RELEASE.jar
Org. springframework. context-3.0.2.RELEASE.jar
Org. springframework. core-3.0.2.RELEASE.jar
Org. springframework. expression-3.0.2.RELEASE.jar
Org. springframework. Web. servlet-3.0.2.RELEASE.jar
Org. springframework. web-3.0.2.RELEASE.jar
- Spring framework Dependencies
Com.springsource.org. aopalliance-1.0.0.jar in org. aopalliance
In edu. Emory. mathcs. backport
Com.springsource.edu. Emory. mathcs. backport-3.0.0.jar
Com.springsource.net. SF. cglib-2.2.0.jar in net. SourceForge. cglib
[Note:] It is very convenient to use ivy or Maven to manage the dependency packages of spring 3. After completing this series of tutorials, I will sort this part separately. Copy it manually.
- Spring blazeds Integration
Org. springframework. flex-1.5.0.CI-498.jar
Step 2: Modify the Web. xml file
<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app
Id = "webapp_id"
Version = "2.4"
Xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<Display-Name> Zara </display-Name>
<Context-param>
<Param-Name> Flex. Class. Path </param-Name>
<Param-value>/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars </param-value>
</Context-param>
<! -- HTTP flex session attribute and binding listener support -->
<Listener>
<Listener-class> Flex. messaging. httpflexsession </listener-class>
</Listener>
<Welcome-file-List>
<Welcome-File> index.html </welcome-File>
<Welcome-File> index.htm </welcome-File>
<Welcome-File> index. jsp </welcome-File>
<Welcome-File> default.html </welcome-File>
<Welcome-File> default.htm </welcome-File>
<Welcome-File> default. jsp </welcome-File>
</Welcome-file-List>
<! -- Define spring and spring flex integration configurations -->
<Servlet>
<Servlet-Name> messagebrokerservlet </servlet-Name>
<Servlet-class> org. springframework. Web. servlet. dispatcherservlet </servlet-class>
<Init-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value>/WEB-INF/classes/META-INF/applicationcontext. xml </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
<! -- Map/spring/* requests to the dispatcherservlet -->
<Servlet-mapping>
<Servlet-Name> messagebrokerservlet </servlet-Name>
<URL-pattern>/messagebroker/* </url-pattern>
</Servlet-mapping>
<! -- Define the end of spring and spring flex integration configuration -->
<! -- Access RDS definition start -->
<Servlet>
<Servlet-Name> rdsdispatchservlet </servlet-Name>
<Display-Name> rdsdispatchservlet </display-Name>
<Servlet-class> Flex. RDS. server. servlet. frontendservlet </servlet-class>
<Init-param>
<Param-Name> useappserversecurity </param-Name>
<Param-value> false </param-value>
</Init-param>
<Init-param>
<Param-Name> messagebrokerid </param-Name>
<Param-value> _ messagebroker </param-value>
</Init-param>
<Load-on-startup> 10 </load-on-startup>
</Servlet>
<Servlet-Mapping
Id = "rds_dispatch_mapping">
<Servlet-Name> rdsdispatchservlet </servlet-Name>
<URL-pattern>/cfide/main/ide. cfm </url-pattern>
</Servlet-mapping>
<! -- End of RDS access definition -->
</Web-app>
Step 3: Configure web-application-config.xml
- Create the application context configuration file applicationcontext. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: context = "http://www.springframework.org/schema/context" xsi: schemalocation = "http://www.springframework.org/schema/beans </P> <p> http://www.springframework.org/schema/beans/spring-beans.xsd </P> <p> http://www.springframework.org/schema/context </P> <p> G/Schema/Context/spring-context.xsd "> <br/> <context: component-scan base-package =" com. Alcor "/> <! -- Scan rules --> <br/> <import resource = "JPA. XML "/> <br/> <import resource =" Alcor. XML "/> <br/> <import resource =" springflex. XML "/> <br/> <! -- Import resource = "security. xml"/--> <br/> </beans>
Step 4: Configure springflex. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans <br/> xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: Flex = "http://www.springframework.org/schema/flex" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xsi: schemalocation = "http://www.springframework.org/schema/beans </P> <p> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd </P> <p> http://www.springframework.org/schema/flex </P> <p> HTTP: // www. Springframework.org/schema/flex/spring-flex-1.0.xsd "> <br/> <! -- Customize the processor mode and define Ro with tags <br/> <flex: Message-broker> <br/> <flex: config-processor <br/> ref = "messagebrokerconfigprocessor"/> <br/> </flex: message-broker> <br/> <bean <br/> id = "messagebrokerconfigprocessor" <br/> class = "com. softvan. spring. flex. flexmessagebrokerconfigprocessor "> <br/> <property <br/> name =" pattern "<br/> value =" $ {shortname} ro "/> <br/> </Bean> </P> <p> end of the custom processor mode --> </P> <p> <! -- Start with the standard configuration file injection method --> <! -- <Br/> <flex: Message-broker/> <br/> <bean id = "myservice" class = "com. alcor. test. myservice "/> <br/> <flex: remoting-destination ref =" myservice "/> </P> <p> --> <! -- End with the standard configuration file injection method --> <br/> <! -- Start with label injection --> <br/> <flex: Message-broker> <br/> <flex: remoting-service default-channels = "My-AMF"/> <br/> </flex: Message-broker> <br/> <! -- End with Tag injection --> <br/> </beans> <br/>
Step 5: Compile the backend bean and use the tag @ remotingdestination to reveal the interface and call it to the flex client.
Package COM. alcor. test; <br/> Import Java. util. arraylist; <br/> Import Java. util. list; <br/> Import Org. springframework. flex. remoting. remotingdestination; <br/> Import Org. springframework. flex. remoting. remotinginclude; <br/> Import Org. springframework. stereotype. service; <br/> @ service <br/> @ remotingdestination <br/> public class myservice {<br/> @ remotinginclude <br/> public list <myentity> getmyentities () {<br/> List <myentity> List = new arraylist <myentity> (); <br/> myentity entity = new myentity (); <br/> entity. setfirstname ("hello"); <br/> entity. setlastname ("world"); <br/> entity. setemailaddress ("hello@world.com"); <br/> list. add (entity); <br/> myentity entity2 = new myentity (); <br/> entity2.setfirstname ("hello"); <br/> entity2.setlastname ("space "); <br/> entity2.setemailaddress ("hello@space.com"); <br/> list. add (entity2); <br/> myentity entity3 = new myentity (); <br/> entity3.setfirstname ("hello"); <br/> entity3.setlastname ("Neighbor "); <br/> entity3.setemailaddress ("hello@neighbor.com"); <br/> list. add (entity3); <br/> return list; <br/>}< br/>
Note: To use the (data/service) feature in fb4. You can access the backend Java Bean in the editor.
You must create a web project before adding the flex project performance method. This project has the web application and flex application dual.
You cannot directly create a flex project and select to use WTP to integrate Java/flex functions. Otherwise, you cannot use the (data/service) menu in the IDE to access the backend bean.