Xfire 集成 Spring

上篇 <<XFire 建立 WebService>>简单说明如果通过XFire接口和实现类方式和注解方式创建WebService.这里记录下我学到的集成Spring,以便参考.

添加xfire-spring.jar.整合spring与XFire,在<<XFire 建立 WebService>>篇中通过接口和实现类方式基础上实行三部曲

1第一步: 修改web.xml

<?xml version="1.0" encoding="UTF-8"?>  
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
  <servlet>  
    <servlet-name>XFireServlet</servlet-name>  
    <servlet-class>
       org.codehaus.xfire.transport.http.XFireConfigurableServlet
    </servlet-class>  
  </servlet>  
  <servlet-mapping>  
    <servlet-name>XFireServlet</servlet-name>  
    <url-pattern>/services/*</url-pattern>  
  </servlet-mapping>  
</web-app>
修改为

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <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>

</web-app>

2 第二步:编写applicationContext.xml

  2.1使用XFire -spring.jar

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 

<beans>
	<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
        <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter"
		lazy-init="false" abstract="true">
		<property name="serviceFactory" ref="xfire.serviceFactory" />
		<property name="xfire" ref="xfire" />
	</bean>
    
	<bean id="typeImpl" class="com.ywxm.webservice.support.TypeServiceImpl" />
	<bean id="typeService" parent="baseWebService">
		<property name="serviceBean" ref="typeImpl" />
		<property name="serviceClass" value="com.ywxm.webservice.TypeService" />
	</bean>

</beans>

2.2不使用XFire-spring.jar

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   ">
 

<beans>
	<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
        <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter"
		lazy-init="false" abstract="true">
		<property name="serviceFactory" ref="xfire.serviceFactory" />
		<property name="xfire" ref="xfire" />
	</bean>
    
	<bean id="typeImpl" class="com.ywxm.webservice.support.TypeServiceImpl" />
	<bean id="typeService" parent="baseWebService">
		<property name="serviceBean" ref="typeImpl" />
		<property name="serviceClass" value="com.ywxm.webservice.TypeService" />
	</bean>

</beans>

第二步中有两种配发.2.1使用XFire-spring.jar.使用XFire自带的spring包.2.2不使用XFire-spring.jar,其实上面两种方式只是头部不同,可2.1满足不了需求,为何?因为我还需要使用tx,util,context等等.如果用2.1的配置方式,将启动失败(可能是我没找到XFire的方法,如果有知道的,请告诉声.)所有我需要2.2的配置方式.

第三步:删除META-INF/xfire/services

配置虽然完成,但如果项目的功能多,你可以想想一下在第二步中配置几十个,那工作量有多大.幸好XFire可以使用注解方式.

1 修改applicationContext.xml

package com.ywxm.service; 
@WebService
public interface SimpleService {   
    @WebMethod
    public String login(@WebParam String username, String password);  
    @WebMethod
    public void getUser();  
}  

@Component
@WebService(serviceName="SimpleService",endpointInterface="com.ywxm.service.SimpleService")
package com.ywxm.service.support;  
import com.ywxm.service.SimpleService;  
public class SimpleServiceImpl implements SimpleService {  
    public String login(String username, String password) {  
        if (username.equals("") || username == null) {  
            return "交出用户名";  
        }  
        if (password.equals("") || password == null) {  
            return "交出密码";  
        }  
        return "ok";  
    }   
    public void getUser() {  
    }  
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值