flex结合Lcds整合spring
1、下载lcds,安装完成后,解压lcds.war. 2、新建webProject,拷贝解压后的lcds中的所有内容覆盖新建工程的WebRoot中的相应内容。 3、到此为止,我们的工程就有了lcds的功能。 4、发布工程并启动。 5、如果启动过程中没有什么异常,开始整合spring,如果有异常,重复上述几步。 6、为工程添加spring特性,相信用过Myeclipse的童鞋对这个应该不会陌生。 7、在web.xml中增加spring的初始化工作,这里给出我的xml文件内容。 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>LiveCycle Data Services</display-name> <description>LiveCycle Data Services Application</description> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <!-- Spring ContextLoaderListener (Not needed if you don't use Spring) --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Http Flex Session attribute and binding listener support --> <listener> <listener-class>flex.messaging.HttpFlexSession</listener-class> </listener> <!-- MessageBroker Servlet --> <servlet> <servlet-name>MessageBrokerServlet</servlet-name> <display-name>MessageBrokerServlet</display-name> <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class> <init-param> <param-name>services.configuration.file</param-name> <param-value>/WEB-INF/flex/services-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- begin rds <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>true</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 rds --> <servlet-mapping> <servlet-name>MessageBrokerServlet</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list> <!-- for WebSphere deployment,please uncomment --> <!-- <resource-ref> <description>Messaging WorkManager</description> <res-ref-name>wm/MessagingWorkManager</res-ref-name> <res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> --> </web-app>
8、增加一个spring的工厂类,我的上一篇给出了源码,注意如果有编译错误,可能是需要的spring包没有加到buildPath中,请加入所需的spring的包,同样这里再给出源码. package springFactory; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import flex.messaging.FactoryInstance; import flex.messaging.FlexFactory; import flex.messaging.config.ConfigMap; import flex.messaging.services.ServiceException; public class SpringFactory implements FlexFactory { private static final String SOURCE = "source"; public void initialize(String id,ConfigMap configMap) {} public FactoryInstance createFactoryInstance(String id,ConfigMap properties) { SpringFactoryInstance instance = new SpringFactoryInstance(this,id,properties); instance.setSource(properties.getPropertyAsString(SOURCE,instance.getId())); return instance; } // end method createFactoryInstance() public Object lookup(FactoryInstance inst) { SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst; return factoryInstance.lookup(); } static class SpringFactoryInstance extends FactoryInstance { SpringFactoryInstance(SpringFactory factory,String id,ConfigMap properties) { super(factory,properties); } public String toString() { return "SpringFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope(); } public Object lookup() { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext()); String beanName = getSource(); try { return appContext.getBean(beanName); } catch (NoSuchBeanDefinitionException nexc) { ServiceException e = new ServiceException(); String msg = "Spring service named '" + beanName + "' does not exist."; e.setMessage(msg); e.setRootCause(nexc); e.setDetails(msg); e.setCode("Server.Processing"); throw e; } catch (BeansException bexc) { ServiceException e = new ServiceException(); String msg = "Unable to create Spring service named '" + beanName + "' "; e.setMessage(msg); e.setRootCause(bexc); e.setDetails(msg); e.setCode("Server.Processing"); throw e; } } } } 9、在services-config中增加一个spring工厂,注意位置在<security>之前。 <factories> <factory id="spring" class="springFactory.SpringFactory" /> </factories> 10、在remoting-config中增加一个destination。 <?xml version="1.0" encoding="UTF-8"?> <service id="remoting-service" class="flex.messaging.services.RemotingService"> <adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/> </adapters> <default-channels> <channel ref="my-amf"/> </default-channels> <destination id="testHello"> <properties> <factory>spring</factory> <source>hello</source> </properties> </destination> </service> 11、在applicationContext中配置bean。 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="hello" class="flexServer.RemoteObject"></bean> </beans> 12、启动应用,在flex中调用,下面给出我的测试类的源码: package flexServer; public class RemoteObject { public String sayHello(String msg){ return "Hello,"+msg; } public String sayFuck(String msg){ return "fuck,"+msg; } } 13、给出MXML的使用代码: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="534" width="1122"> <mx:Binding source="text_c.text" destination="text_d.text"/> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.controls.Alert; private function callRO(str:String):void{ firstRO.sayFuck(str); firstRO.addEventListener(ResultEvent.RESULT,getROResult); } private function callRO2(str:String):void{ firstRO.sayHello(str); firstRO.addEventListener(ResultEvent.RESULT,getROResult); } private function getROResult(e:ResultEvent) :void { Alert.show(e.result.toString()); } ]]> </mx:Script> <mx:RemoteObject id="firstRO" destination="testHello"/> <mx:Panel width="1108" height="411" layout="absolute" title="我的面板"> <mx:Button click="callRO('stone')" label="fuck" x="420.5" y="328" width="100"/> <mx:Button click="callRO2('stone')" label="Hello" x="572.5" y="328" width="100"/> </mx:Panel> </mx:Application> 14、运行flex吧!看是不是两个按钮都给你打招呼啊!只是有个不太友好啊! ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/3
- c# – 如何检查dynamic是否为空.
- ruby-on-rails – Paperclip:与邮箱宝石的集成
- c# – 有没有办法管理不规则XML文档的更改,就像使用DataTab
- swift:基于MPMoviePlayerController的视频播放器
- ruby-on-rails – 改变设计和轨道3以使用bcrypt而不是sha
- vb.net – 该字段太小,无法接受您尝试添加的数据量.有没有人
- c – 为什么数据类型的最大值显示荒谬的高值?
- ajax UpdateProgress 不显示
- ruby-on-rails – Rails无法登录到postgresql – PG ::错误