1
、想要发布成webservice的类,必须实现接口(Spring2.0,Xfile1.2)<!----><o:p></o:p>
2
、3个配置文件(后面详细说)<o:p></o:p>
----------------------------------------------<o:p></o:p>
HelloRemote.java<o:p></o:p>
package test;<o:p></o:p>
public interface HelloRemote {<o:p></o:p>
public String hello(); <o:p></o:p>
public String helloTo(String name); <o:p></o:p>
public String getJsonData(String pageIndex,String pageSize); <o:p></o:p>
}<o:p></o:p>
----------------------------------------------<o:p></o:p>
HelloBean.java<o:p></o:p>
package test;<o:p></o:p>
import javax.servlet.http.HttpServletRequest;<o:p></o:p>
import javax.servlet.http.HttpSession;<o:p></o:p>
import org.codehaus.xfire.transport.http.XFireServletController;<o:p></o:p>
public class HelloBean implements HelloRemote <o:p></o:p>
{<o:p></o:p>
public String hello() <o:p></o:p>
{<o:p></o:p>
return "hello";<o:p></o:p>
}<o:p></o:p>
public String helloTo(String name) <o:p></o:p>
{<o:p></o:p>
return " hello " + name + "!";<o:p></o:p>
}<o:p></o:p>
private String example() <o:p></o:p>
{<o:p></o:p>
//
使用session<o:p></o:p>
HttpServletRequest request = XFireServletController.getRequest();<o:p></o:p>
HttpSession session = request.getSession(); <o:p></o:p>
return "
请求地址:"+request.getLocalAddr()<o:p></o:p>
+",
会话创建时间:"+session.getCreationTime();<o:p></o:p>
}<o:p></o:p>
public String getJsonData(String pageIndex, String pageSize) <o:p></o:p>
{<o:p></o:p>
String rtnValue = "";<o:p></o:p>
rtnValue = example();<o:p></o:p>
return rtnValue;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
----------------------------------------------<o:p></o:p>
web.xml<o:p></o:p>
<?xml version="1.0" encoding="UTF-8"?><o:p></o:p>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"<o:p></o:p>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<o:p></o:p>
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <o:p></o:p>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><o:p></o:p>
<!--
配置文件路径开始,指定加载的配置文件 --><o:p></o:p>
<context-param><o:p></o:p>
<param-name>contextConfigLocation</param-name><o:p></o:p>
<param-value><o:p></o:p>
/WEB-INF/classes/applicationContext*.xml<o:p></o:p>
classpath:org/codehaus/xfire/spring/xfire.xml<o:p></o:p>
</param-value><o:p></o:p>
</context-param><o:p></o:p>
<!--
启动时加载SpringContextServlet --><o:p></o:p>
<listener><o:p></o:p>
<listener-class><o:p></o:p>
org.springframework.web.context.ContextLoaderListener<o:p></o:p>
</listener-class><o:p></o:p>
</listener><o:p></o:p>
<listener><o:p></o:p>
<listener-class><o:p></o:p>
org.springframework.web.util.IntrospectorCleanupListener<o:p></o:p>
</listener-class><o:p></o:p>
</listener><o:p></o:p>
<!-- XFire
配置 --><o:p></o:p>
<servlet><o:p></o:p>
<servlet-name>xfire</servlet-name><o:p></o:p>
<servlet-class><o:p></o:p>
org.springframework.web.servlet.DispatcherServlet<o:p></o:p>
</servlet-class><o:p></o:p>
</servlet><o:p></o:p>
<servlet-mapping><o:p></o:p>
<servlet-name>xfire</servlet-name><o:p></o:p>
<url-pattern>*.ws</url-pattern><o:p></o:p>
</servlet-mapping><o:p></o:p>
<o:p> </o:p>
<welcome-file-list><o:p></o:p>
<welcome-file>index.jsp</welcome-file><o:p></o:p>
</welcome-file-list><o:p></o:p>
</web-app><o:p></o:p>
这里注意:classpath:org/codehaus/xfire/spring/xfire.xml必须要写进去。<o:p></o:p>
----------------------------------------------<o:p></o:p>
xfire-servlet.xml
新建这个文件,并且和web.xml放在同一个文件夹。<o:p></o:p>
注意: 名称和位置都不能变。<o:p></o:p>
<?xml version="1.0" encoding="UTF-8"?><o:p></o:p>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <o:p></o:p>
"http://www.springframework.org/dtd/spring-beans.dtd"><o:p></o:p>
<beans><o:p></o:p>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"><o:p></o:p>
<property name="urlMap"><o:p></o:p>
<map><o:p></o:p>
<entry key="/myHelloService.ws"><!--
暴露的服务名称 --><o:p></o:p>
<ref bean="myTest" /><o:p></o:p>
</entry><o:p></o:p>
</map><o:p></o:p>
</property><o:p></o:p>
</bean><o:p></o:p>
<bean id="myTest" parent="webService"<o:p></o:p>
class="org.codehaus.xfire.spring.remoting.XFireExporter"><o:p></o:p>
<!--
定义实现类(指向applicationContext-webService.xml) --><o:p></o:p>
<property name="serviceBean"><o:p></o:p>
<ref bean="myHelloBean" /><o:p></o:p>
</property><o:p></o:p>
<!--
定义接口类 --><o:p></o:p>
<property name="serviceClass"><o:p></o:p>
<value>test.HelloRemote</value><o:p></o:p>
</property><o:p></o:p>
</bean><o:p></o:p>
<!-- webService
基本配置 --><o:p></o:p>
<bean id="webService"<o:p></o:p>
class="org.codehaus.xfire.spring.remoting.XFireExporter"<o:p></o:p>
abstract="true"><o:p></o:p>
<property name="serviceFactory"><o:p></o:p>
<ref bean="xfire.serviceFactory" /><o:p></o:p>
</property><o:p></o:p>
<property name="xfire"><o:p></o:p>
<ref bean="xfire" /><o:p></o:p>
</property><o:p></o:p>
</bean><o:p></o:p>
</beans><o:p></o:p>
----------------------------------------------<o:p></o:p>
spring
的配置文件 applicationContext-webService.xml<o:p></o:p>
<?xml version="1.0" encoding="UTF-8"?> <o:p></o:p>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <o:p></o:p>
"http://www.springframework.org/dtd/spring-beans.dtd"> <o:p></o:p>
<beans> <o:p></o:p>
<bean id="myHelloBean" class="test.HelloBean"></bean> <o:p></o:p>
</beans><o:p></o:p>
分享到:
相关推荐
xfire+spring开发webservice 很不错的文档
xfire+spring+webservice+client xfire+spring+webservice+client xfire+spring+webservice+client
webservice教程(xfire+spring)webservice教程(xfire+spring)webservice教程(xfire+spring)webservice教程(xfire+spring)
xfire+spring+webservice xfire+spring+webservice xfire+spring+webservice xfire+spring+webservice
spring+xfire( 编写webservice完整配置+案例)
NULL 博文链接:https://zhangzhaoaaa.iteye.com/blog/1718819
用maven管理的,xfire+spring开发的webservice例子
xfire+spring webservice
2 使用Stax解释XML,性能有了质的提高。XFire采用Woodstox 作Stax实现; 3 容易上手,可以方便快速地从pojo发布服务; 4 支持Spring、Pico、Plexus、Loom等容器; 5 灵活的Binding机制,包括默认的Aegis,...
xFire+spring webService示例 用过的
使用xfire+spring编写webservice例子,供大家学习与交流,是一个完整的实例,里面有说明文档
NULL 博文链接:https://cdxs2.iteye.com/blog/1974525
xfire+Spring整合发布webservice,详细解释配置过程,及是替代码,帮助一部分需要这方面开发的人员。
关于ssh demo 演示验证码及图片流显示在界面中,XFire+Spring构建WebService整合
webservice(xfire)+spring的二种实现方式,里面有详细的配置说明.
基于spring+hibernate +xfire框架开发的webservice 项目
用XFire开发WebService Spring注解
NULL 博文链接:https://jishiweili.iteye.com/blog/2087930
自己写给同事培训的xfire整合spring的小项目 步骤清晰 简单易懂 适合刚刚接触xfire的同事们