搭建Flex41+Spring+Hibernate.docx
- 文档编号:8008438
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:35
- 大小:630.28KB
搭建Flex41+Spring+Hibernate.docx
《搭建Flex41+Spring+Hibernate.docx》由会员分享,可在线阅读,更多相关《搭建Flex41+Spring+Hibernate.docx(35页珍藏版)》请在冰豆网上搜索。
搭建Flex41+Spring+Hibernate
搭建Flex+Hibernate+Spring环境
1.安装MyEclipse8.6
2.安装FlashBuilder_4_Plugin_LS10.exe
3.FlashBuilder安装的过程中需要绑定MyEclipse8.6的路径(绑定的目录下必须有myeclipse.exe文件和dropins文件夹)
4.安装成功后,启动MyEclipse8.6,报错"Aninternalerroroccurredduring:
"InitializingTargetCfg".java.lang.NullPointerException",解决办法是删掉Genuitec\Common\plugins文件夹下面的一个包:
mon.http_3.0.3.v201007291200.jar,然后重启MyEclipse8.6。
但是发现不能创建Web工程,所以我就把这个包又加到了plugins文件夹下面。
就没报错了。
(如果MyEclipse8.5中没有Tomcat服务器,就要安装一个Tomcat插件,方法如下:
将com.sysdeo.eclipse.tomcat_3.2.1文件夹放到D:
\programfiles\Genuitec\Common\plugins,
打开D:
\programfiles\Genuitec\MyEclipse8.5\configuration\org.eclipse.equinox.simpleconfigurator\bundles.info文件,在最后加上com.sysdeo.eclipse.tomcat,3.2.1,file:
/D:
/programfiles/Genuitec/Common/plugins/com.sysdeo.eclipse.tomcat_3.2.1/,4,false重启MyEclipse8.5.window-->preferences-->Tomcat配置一些参数,OK!
)
5.新建web项目HCS
6.添加bleazeds支持
找到已解压的bleazeds文件夹,进入到:
blazeds\WEB-INF
复制flex和lib两个文件夹到HCS下的webRoot/WEB-INF目录下
7.在web.xml文件中添加代码:
--Flex配置-->
--HttpFlexSessionattributeandbindinglistenersupport-->
--MessageBrokerServlet-->
--
8.将web工程添加到tomcat中
启动tomcat
9.添加Flex工程
右键HCS,选择:
添加/更改项目类型—>添加Flex项目类型
注:
服务技术选择如下
10.点Next,如下配置
11.点击Finish,配置Flex项目属性
在Flex视图下,右键properties打开项目属性设置对话框
12.点击OK,这是工程中的没有http-template文件夹,然后在Flex视图下,右键properties打开项目属性设置对话框
将”生成HTML包装器文件”的钩钩去掉,点击Apply,在将此钩钩钩上点击OK,工程下面就会出现http-template文件夹
13,这是http-template文件夹下面的index.template.html文件报错,打开此文件,删除这行注释
--Forversiondetection,settomin.requiredFlashPlayerversion,or0(or0.0.0),fornoversiondetection.-->
保存就没错了
13.到了这个时候基本上已经搭建好Flex+bleazeds的web环境,现在来测试一下
1.)新建一个包:
com.zuohd.hcs.user.web
2.)在包中新一个类:
HelloWorld,作用flex的一个远程对象,HelloWorld中的代码如下
packagecom.zuohd.hcs.user.web;
publicclassHelloWorld{
publicStringsayHelloTo(Stringname){
return"Hello"+name;
}
}
3.)在HCS/WebRoot/WEB-INF/flex/remoting-config.xml注册这个远程对象
4.)在src/HCS.mxml中添加以下代码:
xmlversion="1.0"encoding="utf-8"?
>
Applicationxmlns: mx="layout="absolute"> Script> [CDATA[ privatefunctionremotingSayHello(event: Event): void{ variname: String=tiName.text; say.sayHelloTo(iname); } ]]> Script> RemoteObjectid="say"destination="Hello"> RemoteObject> Buttonx="335"y="80"label="Click"click="remotingSayHello(event);"/> TextInputx="159"y="80"id="tiName"/> Labelx="109"y="82"text="name: "/> Labeltext="{say.sayHelloTo.lastResult}"x="44"y="162"width="448"height="71"id="lblView"color="#FCEE09"fontSize="20"fontWeight="bold"textDecoration="underline"fontStyle="normal"/> Application> 5.)启动tomcat,等tomcat启动好后,右键单击HCS.mxml,选中RunAs—>Web应用程序,效果如下 到了这一步,flex+bleazeds已经完成 14.添加Spring框架,在MyEclipseJavaEnterprise视图下的步骤如下: 点击HCS工程—>MyEclipse—>AddSpringCapabilities 点击Next 点击Finish 点击KeepExisting 15.添加mon,添加SpringFactory.java(网上的) packagemon; importorg.springframework.context.ApplicationContext; importorg.springframework.web.context.support.WebApplicationContextUtils; importorg.springframework.beans.BeansException; importorg.springframework.beans.factory.NoSuchBeanDefinitionException; importflex.messaging.FactoryInstance; importflex.messaging.FlexFactory; importflex.messaging.config.ConfigMap; importflex.messaging.services.ServiceException; /** *Thisinterfaceisimplementedbyfactorycomponentswhichprovide *instancestotheflexmessagingframework.Toconfigureflexdataservices *tousethisfactory,addthefollowinglinestoyourservices-config.xml *file(locatedintheWEB-INF/flexdirectoryofyourwebapplication). * *<factories> *<factoryid="spring"class="flex.samples.factories.SpringFactory"/> *</factories> * *Youalsomustconfigurethewebapplicationtousespringandmustcopythespring.jar *fileintoyourWEB-INF/libdirectory.Toconfigureyourappservertousespring, *youaddthefollowinglinestoyourWEB-INF/web.xmlfile: * *<context-param> *<param-name>contextConfigLocation</param-name> *<param-value>/WEB-INF/applicationContext.xml</param-value> *</context-param> * *<listener> *<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> *</listener> * *ThenyouputyourspringbeanconfigurationinWEB-INF/applicationContext.xml(asperthe *lineabove).Forexample: * *<? xmlversion="1.0"encoding="UTF-8"? > *<! DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN//EN""http: //www.springframework.org/dtd/spring-beans.dtd"> * *<beans> *<beanname="weatherBean"class="dev.weather.WeatherService"singleton="true"/> *</beans> * *Nowyouarereadytodefineadestinationinflexthatmapstothisexistingservice. *Todothisyou'daddthistoyourWEB-INF/flex/remoting-config.xml: * *<destinationid="WeatherService"> *<properties> *<factory>spring</factory> *<source>weatherBean</source> *</properties> *</destination> * *@authorJeffVroom */ publicclassSpringFactoryimplementsFlexFactory { privatestaticfinalStringSOURCE="source"; /** *Thismethodcanbeusedtoinitializethefactoryitself.Itiscalledwithconfiguration *parametersfromthefactorytagwhichdefinestheidofthefactory. */ publicvoidinitialize(Stringid,ConfigMapconfigMap){} /** *Thismethodiscalledwhenweinitializethedefinitionofaninstance *whichwillbelookedupbythisfactory.Itshouldvalidatethat *thepropertiessuppliedarevalidtodefineaninstance. *Anyvalidpropertiesusedforthisconfigurationmustbeaccessedto *avoidwarningsaboutunusedconfigurationelements.Ifyourfactory *isonlyusedforapplicationscopedcomponents,thismethodcansimply *returnafactoryinstancewhichdelegatesthecreationofthecomponent *totheFactoryInstance'slookupmethod. */ publicFactoryInstancecreateFactoryInstance(Stringid,ConfigMapproperties) { SpringFactoryInstanceinstance=newSpringFactoryInstance(this,id,properties); instance.setSource(properties.getPropertyAsString(SOURCE,instance.getId())); returninstance; }//endmethodcreateFactoryInstance() /** *Returnstheinstancespecifiedbythesource *andpropertiesarguments.Forthefactory,thismaymean *constructinganewinstance,optionallyregisteringitinsomeother *namespacesuchasthesessionorJNDI,andthenreturningit *oritmaymeancreatinganewinstanceandreturningit. *Thismethodiscalledforeachrequesttooperateonthe *givenitembythesystemsoitshouldberelativelyefficient. * *Ifyourfactorydoesnotsupportthescopeproperty,it *reportanerrorifscopeissuppliedintheproperties *forthisinstance. */ publicObjectlookup(FactoryInstanceinst) { SpringFactoryInstancefactoryInstance=(SpringFactoryInstance)inst; returnfactoryInstance.lookup(); } staticclassSpringFactoryInstanceextendsFactoryInstance { SpringFactoryInstance(SpringFactoryfactory,Stringid,ConfigMapproperties) { super(factory,id,properties); } publicStringtoString() { return"SpringFactoryinstanceforid="+getId()+"source="+getSource()+"scope="+getScope(); } publicObjectlookup() { ApplicationContextappContext=WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext()); StringbeanName=getSource(); try { returnappContext.getBean(beanName); } catch(NoSuchBeanDefinitionExceptionnexc) { ServiceExceptione=newServiceException(); Stringmsg="Springservicenamed'"+beanName+"'doesnotexist."; e.setMessage(msg); e.setRootCause(nexc); e.setDetails(msg); e.setCode("Server.Processing"); throwe; } catch(BeansExceptionbexc) { ServiceExceptione=newServiceException(); Stringmsg="UnabletocreateSpringservicenamed'"+beanName+"'"; e.setMessage(msg); e.setRootCause(bexc); e.setDetails(msg); e.setCode("Server.Processing"); throwe; } } } } 16.在WEB-INF/flex中的services-config.xml中注册SpringFactory工厂 17.在WEB-INF文件夹下建立conf文件夹,将applicationContext.xml移入此中,在WEB-INF/web.xml中加入对spring的支持 --Spring配置--> --Backendconfiguration--> /WEB-INF/conf/*/spring-*.xml, /WEB-INF/conf/applicationContext.xml org.springframework.web.context.ContextLoaderServlet
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 搭建 Flex41 Spring Hibernate
![提示](https://static.bdocx.com/images/bang_tan.gif)