您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > Xfire+Spring+Hibernate+发布WebService
XfireSpring1.2Hibernate3发布WebService一、准备工作1、下载安装EclipseVersion:3.3.1.1和MyEclipse6.0.12、下载安装MySQLServer5.13、下载MySQL驱动mysql-connector-java-5.0.8-bin.jar4、使用MySQL管理工具创建数据库easyLife和一张user表。我使用的是EMSSQLManager2007forMySQL。表结构如下:idintegerusernameVarchar(20)userpwdVarchar(20)插入一条数据待测试用。5、安装Tomcat5.5二、实例代码连接数据库打开MyEclipseDatabaseExplorer新建一个数据连接如图:创建项目1、打开MyEclipse新建一个WebServiceProject项目输入项目名称XfireWebService。2、下一步默认3、下一步,勾选XFire1.2HTTPClientLibraries。4、点击Viewandeditlibraries去掉spring-1.2.6.jar这个包(不去掉会和后面添加的Spring冲突)5、右键添加MyEclipse的SpringCapabilities,方便起见选上所有的包,选择Copychecked…,下一步默认完成。6、再添加HibernateCapabilities,同样选上所有包。下一步下一步下一步下一步去掉复选框完成。点击Replace替换所有包7、然后配置web.xml?xmlversion=1.0encoding=UTF-8?web-appxmlns=:xsi==2.4xsi:schemaLocation=://java.sun.com/xml/ns/j2ee/web-app_2_4.xsdcontext-paramparam-namecontextConfigLocation/param-nameparam-value/WEB-INF/classes/applicationContext.xmlclasspath:org/codehaus/xfire/spring/xfire.xml/param-value/context-paramlistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listenerservletservlet-namexfire/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class/servletservlet-mappingservlet-namexfire/servlet-nameurl-pattern/services/*/url-pattern/servlet-mapping/web-app8、建立一个com.easylife包,再新建一个webservice下一步下一步填入如图内容,完成。9、修改ILoginDAOpackagecom.easylife;//GeneratedbyMyEclipsepublicinterfaceILoginDAO{publicbooleanlogin(Stringusername,Stringuserpwd);}修改LoginDAOImplpackagecom.easylife;importjava.util.List;importorg.hibernate.Query;importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;//GeneratedbyMyEclipsepublicclassLoginDAOImplextendsHibernateDaoSupportimplementsILoginDAO{@SuppressWarnings(unchecked)publicbooleanlogin(Stringusername,Stringuserpwd){booleanflag=false;Stringhql=FROMUserASuWHEREu.username=?ANDu.userpwd=?;Queryq=super.getSession().createQuery(hql);q.setString(0,username);q.setString(1,userpwd);Listall=q.list();if(all.size()0){flag=true;//SysUserst=(SysUsers)all.get(0);}returnflag;}}10、打开MyEclipseDataExplorer视图找到user表使用HibernateReverseEngineering下一步选择下一步默认完成11、在applicationContext.xml末尾添加一个beanbeanid=LoginDAOImplclass=com.easylife.LoginDAOImplpropertyname=sessionFactoryrefbean=sessionFactory//property/bean12、在WEB-INF下建立xfire-servlet.xml?xmlversion=1.0encoding=UTF-8?!DOCTYPEbeansPUBLIC-//SPRING//DTDBEAN//EN=org.springframework.web.servlet.handler.SimpleUrlHandlerMappingpropertyname=urlMapmapentrykey=/Login!--此为服务名--refbean=login//entry/map/property/beanbeanid=loginclass=org.codehaus.xfire.spring.remoting.XFireExporterpropertyname=serviceFactoryrefbean=xfire.serviceFactory//propertypropertyname=xfirerefbean=xfire//propertypropertyname=serviceBeanrefbean=LoginDAOImpl/!--在applicationContext.xml中装配的类--/propertypropertyname=serviceClassvaluecom.easylife.ILoginDAO/value!--接口--/property/bean/beans13、部署项目14、测试服务返回?xmlversion=1.0encoding=UTF-8?wsdl:definitionstargetNamespace===:soap12=:xsd=:soapenc11=:soapenc12=:soap11=:wsdl=:typesxsd:schemaxmlns:xsd==qualifiedelementFormDefault=qualifiedtargetNamespace==loginxsd:complexTypexsd:sequencexsd:elementmaxOccurs=1minOccurs=1name=in0nillable=truetype=xsd:string/xsd:elementmaxOccurs=1minOccurs=1name=in1nillable=truetype=xsd:string//xsd:sequence/xsd:complexType/xsd:elementxsd:elementname=loginResponsexsd:complexTypexsd:sequencexsd:elementmaxOccurs=1minOccurs=1name=outtype=xsd:boolean//xsd:sequence/xsd:complexType/xsd:element/xsd:schema/wsdl:typeswsdl:messagename=loginResponsewsdl:partname=parameterselement=tns:loginResponse/wsdl:part/wsdl:messagewsdl:messagename=loginRequestwsdl:partname=parameterselement=tns:login/wsdl:part/wsdl:messagewsdl:portTypename=ILoginDAOPortTypewsdl:operationname=loginwsdl:inputname=loginRequestmessage=tns:loginRequest/wsdl:inputwsdl:outputname=loginResponsemessage=tns:loginResponse/wsdl:output/wsdl:operation/wsdl:portTypewsdl:bindingname=ILoginDAOHttpBindingtype=tns:ILoginDAOPortTypewsdlsoap:bindingstyle=documenttransport=:operationname=loginwsdlsoap:operationsoapAction=/wsdl:inputname=loginRequestwsdlsoap:bodyuse=literal//wsd
本文标题:Xfire+Spring+Hibernate+发布WebService
链接地址:https://www.777doc.com/doc-5012913 .html