1、- Http Flex Session attribute and binding listener support -listenerlistener-classflex.messaging.HttpFlexSession/listener- MessageBroker Servlet -servletservlet-nameMessageBrokerServlet -/display-name-servlet-classflex.messaging.MessageBrokerServletinit-paramparam-nameservices.configuration.filepara
2、m-value/WEB-INF/flex/services-config.xml/init-paramload-on-startup1/servletservlet-mappingurl-pattern/messagebroker/*/servlet-mapping8. 将web工程添加到tomcat中启动tomcat9. 添加Flex工程 右键HCS,选择:添加/更改项目类型添加Flex项目类型注:服务技术选择如下10.点Next,如下配置11.点击Finish,配置Flex 项目属性 在Flex视图下,右键 properties打开项目属性设置对话框12.点击OK,这是工程中的没有http
3、-template文件夹,然后在Flex视图下,右键 properties打开项目属性设置对话框将”生成HTML包装器文件”的钩钩去掉,点击Apply,在将此钩钩 钩上 点击OK,工程下面就会出现http-template文件夹13,这是http-template文件夹下面的index.template.html文件报错,打开此文件,删除这行注释- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. -保存就没错了13. 到了这个
4、时候基本上已经搭建好Flex+bleazeds的web环境,现在来测试一下 1.)新建一个包:com.zuohd.hcs.user.web 2.) 在包中新一个类:HelloWorld,作用flex的一个远程对象,HelloWorld中的代码如下package com.zuohd.hcs.user.web;public class HelloWorld public String sayHelloTo(String name) return Hello +name; 3.) 在HCS/WebRoot/WEB-INF/flex/remoting-config.xml注册这个远程对象destina
5、tion id=Hello com.zuohd.hcs.user.web.HelloWorld/properties/destination 4.) 在src/HCS.mxml 中添加以下代码:?xml version=1.0 encoding=utf-8mx:Application xmlns:mx= layout=absoluteScriptCDATA private function remotingSayHello(event:Event):void var iname:String=tiName.text; say.sayHelloTo(iname); /mx:RemoteObjec
6、t id=say destination= RemoteObjectButton x=335 y=80 label= Click click=remotingSayHello(event);/TextInput x=159 id=tiNameLabel x=10982 text=name:Label text=say.sayHelloTo.lastResult x=44162 width=448 height=71lblView color=#FCEE09 fontSize=20 fontWeight=bold textDecoration=underline fontStyle=normal
7、Application5.) 启动tomcat,等tomcat启动好后,右键单击HCS.mxml,选中Run AsWeb应用程序,效果如下到了这一步,flex+bleazeds已经完成14.添加Spring框架,在MyEclipse Java Enterprise视图下的步骤如下: 点击HCS工程MyEclipseAdd Spring Capabilities点击Next点击Finish点击Keep Existing15. 添加mon,添加SpringFactory.java(网上的) package mon;import org.springframework.context.Applica
8、tionContext;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.c
9、onfig.ConfigMap;import flex.messaging.services.ServiceException;/* * This interface is implemented by factory components which provide * instances to the flex messaging framework. To configure flex data services * to use this factory, add the following lines to your services-config.xml * file (locat
10、ed in the WEB-INF/flex directory of your web application). * * <factories>factory id=spring class=flex.samples.factories.SpringFactory /&/factories& * You also must configure the web application to use spring and must copy the spring.jar * file into your WEB-INF/lib directory. To configure you
11、r app server to use spring, * you add the following lines to your WEB-INF/web.xml file:context-param¶m-name&contextConfigLocation&/param-name¶m-value&/WEB-INF/applicationContext.xml&/param-value&/context-param&listener&listener-class&org.springframework.web.context.ContextLoaderListener&/lis
12、tener-class&/listener& * * Then you put your spring bean configuration in WEB-INF/applicationContext.xml (as per the * line above). For example:UTF-8&DOCTYPE beans PUBLIC -/SPRING/DTD BEAN/ENhttp:/www.springframework.org/dtd/spring-beans.dtdbeans&bean name=weatherBeandev.weather.WeatherService singl
13、eton=true/&/beans& * Now you are ready to define a destination in flex that maps to this existing service. * To do this youd add this to your WEB-INF/flex/remoting-config.xml:WeatherServiceproperties&factory&spring&/factory&source&weatherBean&/source&/properties&/destination& * author Jeff Vroom */p
14、ublic class SpringFactory implements FlexFactory private static final String SOURCE = source; /* * This method can be used to initialize the factory itself. It is called with configuration * parameters from the factory tag which defines the id of the factory. public void initialize(String id, Config
15、Map configMap) * This method is called when we initialize the definition of an instance * which will be looked up by this factory. It should validate that * the properties supplied are valid to define an instance. * Any valid properties used for this configuration must be accessed to * avoid warning
16、s about unused configuration elements. If your factory * is only used for application scoped components, this method can simply * return a factory instance which delegates the creation of the component * to the FactoryInstances lookup method. public FactoryInstance createFactoryInstance(String id, C
17、onfigMap properties) SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties); instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId(); return instance; / end method createFactoryInstance() * Returns the instance specified by the source * and properties arg
18、uments. For the factory, this may mean * constructing a new instance, optionally registering it in some other * name space such as the session or JNDI, and then returning it * or it may mean creating a new instance and returning it. * This method is called for each request to operate on the * given
19、item by the system so it should be relatively efficient. * * If your factory does not support the scope property, it * report an error if scope is supplied in the properties * for this instance. public Object lookup(FactoryInstance inst) SpringFactoryInstance factoryInstance = (SpringFactoryInstance
20、) inst; return factoryInstance.lookup(); static class SpringFactoryInstance extends FactoryInstance SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties) super(factory, id, properties); public String toString() return SpringFactory instance for id= + getId() + source= + getSo
21、urce() + scope= + getScope(); public Object lookup() ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext(); String beanName = getSource(); try return appContext.getBean(beanName); catch (NoSuchBeanDefinit
22、ionException 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)Unable to create Spring service named e.setRoot
23、Cause(bexc);16. 在WEB-INF/flex中的services-config.xml中注册SpringFactory工厂factoriesmon.SpringFactory/factories17. 在WEB-INF文件夹下建立conf文件夹,将applicationContext.xml 移入此中,在WEB-INF/web.xml中加入对spring的支持- Spring配置 - Backend configuration -context-paramcontextConfigLocationSpringContextServlet org.springframework.web.context.ContextLoaderServletSprin
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1