Spring2.5+Hibernate3.2+xfire开发webservice工程
来源:互联网 发布:淘宝开店的货源怎么找 编辑:程序博客网 时间:2024/05/16 15:14
- <servlet>
- <servlet-name>XFireServlet</servlet-name>
- <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
- <load-on-startup>0</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>XFireServlet</servlet-name>
- <url-pattern>/services/*</url-pattern>
- </servlet-mapping>
<servlet> <servlet-name>XFireServlet</servlet-name> <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class> <load-on-startup>0</load-on-startup></servlet><servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/services/*</url-pattern></servlet-mapping>
首先声明看本案例需要对spring Hibernate有初步了解,否则可能会比较吃力。
按照顺序添加相应的框架。
先添加spring,不用多说什么吧?应该都会的。如果不知道添加什么包,全部选上行了。够简单吧。
然后添加Hibernate,配置文件使用spring的。不需要创建HibernateSessionFactory。呵呵
然后添加xfire。也不是很困难呀。添加就行了。在这里呢。就要说几句了,最好是把xfire相应的包考到工程lib下面,否则你会很郁闷的。先不说了,按照正常的思路来配置吧。添加好了,你会发现
web.xml中增加了
这些是XFire的配置文件,删掉就行了,要不你还要改东西,是不是还缺少点什么呢,对啦,缺少spring的配置文件,现在需要将下面的代码拷贝到配置文件中
- <!-- begin Spring配置 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/xfire-servlet.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <listener>
- <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
- </listener>
- <!-- end Spring配置 -->
- <!-- begin XFire 配置 -->
- <servlet>
- <servlet-name>xfire</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>xfire</servlet-name>
- <url-pattern>*.ws</url-pattern>
- </servlet-mapping>
- <servlet>
- <!-- 配合Spring容器中XFire一起工作的Servlet-->
- <servlet-name>xfireServlet</servlet-name>
- <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>xfireServlet</servlet-name>
- <!-- 在这个URI下开放Web Service服务 -->
- <url-pattern>/service/*</url-pattern>
- </servlet-mapping>
- <!-- end XFire 配置 -->
<!-- begin Spring配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/xfire-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <!-- end Spring配置 --> <!-- begin XFire 配置 --> <servlet> <servlet-name>xfire</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>xfire</servlet-name> <url-pattern>*.ws</url-pattern> </servlet-mapping> <servlet> <!-- 配合Spring容器中XFire一起工作的Servlet--> <servlet-name>xfireServlet</servlet-name> <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>xfireServlet</servlet-name> <!-- 在这个URI下开放Web Service服务 --> <url-pattern>/service/*</url-pattern> </servlet-mapping> <!-- end XFire 配置 -->
这段配置文件是完整的啦,呵呵,拷贝上去就行了。
然后需要在/WEB-INF/目录下 创建xfire-servlet.xml文件备用。
文件内的内容
- <?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:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
- <!--将来所有的web服务信息就要写在这里了。-->
- </beans>
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"><!--将来所有的web服务信息就要写在这里了。--></beans>
好了,现在部署项目了,基本上我们的webservice服务已经搭建好了,启动tomcat吧。
哈哈,是不是发现报错啦,这个原因是因为xfire中默认已经为我们封装了 spring-1.2.6.jar 这么一个jar包,比较累的法子就是自己从tomcat中将这个jar包删掉,比较省事的呢就是新建一个工程,手动为项目添加xfire框架,我是用的后者,前者比较简单,就是在发布的时候比较麻烦,需要每次都去删除这个jar包,当然这里就不普及手动搭建框架的知识了,自己上网查资料吧。
好啦,spring-1.2.6.jar包删掉了,在启动,是不是正常了?
OK,现在我们的web服务系统 已经基本上搭建完成了,是不是该添加个类测试一下了,好说干就干。
到这里就需要重新提提那些话题了,本资料不是普及spring+Hibernate的,所以就不做太详细的介绍了
还是最简单的helloworld,新建一个helloworld吧
新建接口
- public interface HelloWorld {
- public String hello(String name);
- }
public interface HelloWorld {public String hello(String name);}
新建类并实现接口
- public class HelloworldImpl implements HelloWorld {
- public String hello(String name){
- return name+" say: helloWorld!!!";
- }
- }
public class HelloworldImpl implements HelloWorld { public String hello(String name){ return name+" say: helloWorld!!!"; }}
spring配置文件
- <bean id="HelloworldI" class="HelloworldImpl"><!--依然还是很简单。-->
<bean id="HelloworldI" class="HelloworldImpl"><!--依然还是很简单。-->
厉害的就在xfire-servlet.xml文件中了,现在贴上内容,下面大部分信息是固定的,基本上拷贝上去就能用了。
- <!-- 引入XFire预配置信息 -->
- <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
- <!-- 定义访问的url -->
- <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
- <property name="urlMap">
- <map>
- <!-- 显示WebService 访问路径,有几个路径就需要 配置几个路径。 -->
- <entry key="/Helloworld.ws">
- <ref bean="HelloworldWS" /><!--与下面的是对应的。-->
- </entry>
- </map>
- </property>
- </bean>
- <!-- 使用XFire导出器 -->
- <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true">
- <!-- 引用xfire.xml中定义的工厂 -->
- <property name="serviceFactory" ref="xfire.serviceFactory" />
- <!-- 引用xfire.xml中的xfire实例 -->
- <property name="xfire" ref="xfire" />
- </bean>
- <bean id="HelloworldWS" parent="baseWebService"><!-- 服务请求的地址,与上面访问的url地址是对应的 -->
- <!-- 业务服务bean --><!-- 我定义的接口的实现类 -->
- <property name="serviceBean" ref="HelloworldI" /><!--与spring配置文件中的是对应的-->
- <!-- 业务服务bean的窄接口类 --><!-- 我定义的接口 -->
- <property name="serviceClass" value="HelloWorld" /><!--接口,实现类的接口-->
- </bean>
<!-- 引入XFire预配置信息 --><import resource="classpath:org/codehaus/xfire/spring/xfire.xml" /><!-- 定义访问的url --><bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <!-- 显示WebService 访问路径,有几个路径就需要 配置几个路径。 --> <entry key="/Helloworld.ws"> <ref bean="HelloworldWS" /><!--与下面的是对应的。--> </entry> </map> </property></bean><!-- 使用XFire导出器 --><bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true"> <!-- 引用xfire.xml中定义的工厂 --> <property name="serviceFactory" ref="xfire.serviceFactory" /> <!-- 引用xfire.xml中的xfire实例 --> <property name="xfire" ref="xfire" /></bean><bean id="HelloworldWS" parent="baseWebService"><!-- 服务请求的地址,与上面访问的url地址是对应的 --> <!-- 业务服务bean --><!-- 我定义的接口的实现类 --> <property name="serviceBean" ref="HelloworldI" /><!--与spring配置文件中的是对应的--> <!-- 业务服务bean的窄接口类 --><!-- 我定义的接口 --> <property name="serviceClass" value="HelloWorld" /><!--接口,实现类的接口--></bean>
Ok,现在就可以发布我们的工程了,http://localhost:8080/webservice/service/HelloWorld?wsdl然后访问这个地址看看是否成功吧。
需要说明的是,这个项目中没有使用到Hibernate,又需要的自行使用即可,我在这里就不做介绍了,因为我相信看这个帖子的朋友应该对ssh框架有过初步的了解了已经。如果实在不懂的话可以hi我或者Q我均可。
- Spring2.5+Hibernate3.2+xfire开发webservice工程
- xfire+spring2整合开发webservice
- xfire+spring2.5开发webservice接口的两种方式
- xfire+spring2.5开发webservice接口的两种方式
- spring2.5 + hibernate3.2 标注(annotation)开发的简单示例
- Struts2+Spring2.5+Hibernate3.3整合开发
- Struts2+Spring2.5+Hibernate3.3整合开发
- Struts2+Spring2.5+Hibernate3.3整合开发
- struts1.2 + spring2.5 + hibernate3.2框架搭建一之工程总览
- Java : Hibernate3.2 与 Spring2.5整合
- 整合Spring2.5+Struts2.1+Hibernate3.2
- dwr2.0+spring2.5+hibernate3.2整合
- Spring2.5 + Hibernate3.2 集成实例(CTO)
- Spring2.5+Hibernate3.2+Struts2.0配置
- Struts2.1.6 + Spring2.5+Hibernate3.2整合
- Struts1.3 +hibernate3.2+Spring2.5整合
- hibernate3.2与spring2.5集成
- xfire在Myeclipse6.0以上开发webservice工程
- ubuntu 批量修改文件名 右键添加打开终端
- TCP/UDP/HTTP
- POI解析2003Excel、2007Excel
- 查看宏展开之后的代码
- datagridview中输入密码,显示星号*
- Spring2.5+Hibernate3.2+xfire开发webservice工程
- Java Web Start (2)
- 键盘Enter键实现提交表单
- PreferenceActivity详解
- tabbar改变颜色
- linux下mysql出现的几个小问题
- windows7下调试ASP+ACCESS错误“未找到提供程序 该程序可能未正确安
- 吸气温度和压力分析
- 值得收藏的北京移动短信代码