XFire与spring进行整合正确方式

前言:最近看的源码里有关于XFire与spring的整合,所以就想了解下这个整合的过程和配置方式,结果在网上找了很多配置的过程,许多不提供jar包,只是说用myeclipse自己加入XFire库,但我自己用的eclipse开发的,所以就只能自己找jar包,真心醉,网上大部分的jar包要不是错的,要不就不全,就这么一个看起来挺简单的整合用掉了我很长的时间,很心疼,下载的资源要不是就是需要csdn积分要不就是需要注册,是否有人和我一样一没积分,二不喜欢注册。。,并且许多的博客内容是一样的,除了抄就是抄,运行都运行不了就抄过去了。自己写一篇XFire与spring的整合,因为现在大部分都用CXF框架来做webService了,所以里面的一些内容并没有很深入的了解,看XFire的官网都不知道该怎么下载jar文件,英语不好真心伤不起。

一般常用的配置方式有两种:

方式1.使用org.codehaus.xfire.spring.XFireSpringServlet与ServiceBean来发布webService

流程: 1.创建提供服务的接口

    2.创建提供服务接口的实现类

    3.配置web.xml文件

    4.配置spring的配置文件:

导入jar包:XmlSchema-1.1.jar,xfire-all-1.2.6.jar,wsdl4j-1.6.1.jar,org.springframework.web-3.1.1.RELEASE.jar,org.springframework.web.servlet-3.1.1.RELEASE.jar,org.springframework.expression-3.1.1.RELEASE.jar,org.springframework.core-3.1.1.RELEASE.jar,org.springframework.context-3.1.1.RELEASE.jar,org.springframework.beans-3.1.1.RELEASE.jar,org.springframework.asm-3.1.1.RELEASE.jar,org.springframework.aop-3.1.1.RELEASE.jar,jdom-1.0.jar,commons-logging-1.1.1.jar,commons-httpclient-3.0.jar,commons-codec-1.3.jar   加红吧,期间最头疼的就是这些jar文件,要不就是找的是错的,就不就是不全,要不就是xfire与spring的版本冲突,获取需要条件下载!!!伤心总是如此。另外注意这个xfire的jar包已经全部导入了,不需要再导入其他的xfire的jar包

1 2 这里提供服务的接口和实现类我就不写了,我会在配置文件中写清楚的

3.配置web.xml文件:一般是配置spring配置文件的位置,spring的监听器,配置核心控制器

<!--配置spring配置文件的路径,后面还会配置一个spring的监听器,在服务器开启的时会自动加载spring的配置文件。   -->

classpath指的是classes目录下

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext_two.xml
</param-value>
</context-param>
   

<!-- spring的监听器 -->

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- XFire的核心servlet -->
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>



在src下配置applicationContext_two.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>


<bean name="userService" class="org.codehaus.xfire.spring.ServiceBean">
<!-- 提供服务接口的实现类 -->
<property name="serviceBean" ref="userServiceImpl"/>
<!-- 提供服务的接口,这个接口是向客户端进行暴露,里面的方法都可以被客户端所访问 -->
<property name="serviceClass" value="com.union.sx.service.UserService"/>
</bean>

<bean id="userServiceImpl" class="com.union.sx.service.impl.UserServiceImpl"/>
</beans
>

我也不知道为什么要import xfire.xml文件,我的项目中并没有这个文件。

然后开启服务器就可以访问这个网站了

http://localhost:8080/项目名/services/userService 然后选择wsdl


方式2:直接集成Spring(通过Spring的org.springframework.web.servlet.DispatcherServlet)

流程:

1.创建提供服务的接口

    2.创建提供服务接口的实现类

    3.配置web.xml文件

    4.配置spring的配置文件:

导包:还需要另外加入spring的aop的jar文件,不止一个哦

这次就直接从第三步开始了:

<context-param>
<param-name>contextConfigLocation</param-name>

<!-- 依然不知道这个文件是何方神圣,并且整个配置里没有指向一个叫xfire-servlet.xml的文件,但仍然需要我去配置这个文件,这个也百度过,现在越来越感觉百度难用了,不知道用什么引擎。搜索到的好多都是没用的,向找到自己用的很难,有好的引擎可以留言给我噢~ -->

<param-value>
classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>/*</url-pattern>
</servlet-mapping>


在WEB-INF下配置xfire-servler.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop                                        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">


<!-- START SNIPPET: xfire -->
<bean id="userServiceImpl" class="com.union.sx.service.impl.UserServiceImpl"/>
<!-- 将提供服务的接口和实现绑定一个bean上-->
<bean id="userService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<!-- 母鸡啊 -->
<property name="serviceFactory">
<ref bean="xfire.serviceFactory"/>
</property>
<!-- 母鸡啊 -->
<property name="xfire">
<ref bean="xfire"/>
</property>
<!--配置提供服务的实现类 -->
<property name="serviceBean">
<ref bean="userServiceImpl"/>
</property>
<!-- 配置提供服务的接口 -->
<property name="serviceClass">
<value>com.union.sx.service.UserService</value>
</property>
</bean>
<!-- 将提供的服务绑定到指定的地址上去:外部服务器访问时的地址是:http:提供服务的ip:端口号/项目名/key(如果xfire的有拦截路径时,需要在key前面加一个拦截路径目录) -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<!-- 将提供服务的bean绑定到指定的地址上. -->
<entry key="/otherService">
<ref bean="userService"/>
</entry>
</map>
</property>
</bean>
<!-- END SNIPPET: xfire -->
</beans>


心酸,如果有疑问可以给我留言,我把资源挂到csdn上,可以自己去下载,能不能找到就看你翻的多勤快了,不要积分,不想让更多的人受阻,连一门语言都是开源的,没有限制,想不通你们为什么要阻截自己的同行,愿与我同行的更进一步。

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值