XFire集成Spring配置

1.在项目的src下建了一个xfireservice的包,然后在这个包下建了一个名为XFireService的接口和XFireServiceImpl这个实现接口的类。把相关的jar文件添加进项目里。

XFireService.java接口

package xfireservice;
public interface XFireService {
public String sayHello();
}

XFireServiceImpl.java
package xfireservice;
import org.springframework.stereotype.Component;
@Component("XFireService")
public class XFireServiceImpl implements XFireService {
public String sayHello() {
return "Hello World!";
}
}

2.在放置配置文件的包里新建一个xfireService.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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
<bean id="XFireServiceImpl" class="xfireservice.XFireServiceImpl"></bean>
<bean id="XFireServiceImpl.xfire"
class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory" ref="xfire.serviceFactory"></property>
<property name="xfire" ref="xfire"></property>
<property name="serviceBean" ref="XFireServiceImpl"></property>
<property name="serviceClass" value="xfireservice.XFireService"></property>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/XFireServiceImpl">XFireServiceImpl.xfire</prop>
</props>
</property>
</bean>
</beans>


3. 在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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:xfireService.xml
</param-value>
</context-param>
<servlet>
<servlet-name>XFireService</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:xfireService.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>XFireService</servlet-name>
<url-pattern>/xfireservice/*</url-pattern>
</servlet-mapping>



上面这几个都配置完以后,启动tomcat就可以访问了,我项目里的路径为http://localhost:8080/arweb/xfireservice/XFireService?wsdl
我在配置时,最后遇到了一个问题,在web.xml文件中,我的servlet-class写的是<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>,启动项目后访问的时候报404错误,后来改成<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>这个就可以了,这应该是和我引进的包有影响,而且我的项目是用Spring框架写的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.xfire.core.client; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; import com.xfire.core.entity.UserInfo; import com.xfire.core.service.IUserInfoService; /** *@author jilongliang *@Date 2012-3-5 * */ public class UserInfoClient { public static void main(String[] args) { getServiceList(); setServiceList(); } static String url = "http://localhost:8081/xfire/services/UserInfo"; /** * */ public static void getServiceList() { Service service = new ObjectServiceFactory() .create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService) new XFireProxyFactory() .create(service, url); List list = (ArrayList) iAddressService .getAddressList(); System.out.println("一共多少条数据:" + list.size()); for (Iterator iter = list.iterator(); iter.hasNext();) { UserInfo a = iter.next(); System.out.println(a); } } catch (MalformedURLException e) { e.printStackTrace(); } } public static void setServiceList() { Service service = new ObjectServiceFactory() .create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService) new XFireProxyFactory() .create(service, url); List listAdd = new ArrayList(); UserInfo address = new UserInfo(); address.setIdentifier(1); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress("廣東陽春"); address.setPostCode("1111111"); address.setExist(false); address.setArrary(new String[] { "22", "23", "24" }); listAdd.add(address); address.setIdentifier(2); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress(

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值