六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 16|回复: 0

XFire集成Spring配置

[复制链接]

升级  66%

118

主题

118

主题

118

主题

举人

Rank: 3Rank: 3

积分
398
 楼主| 发表于 2013-2-3 10:35:51 | 显示全部楼层 |阅读模式
1.在项目的src下建了一个xfireservice的包,然后在这个包下建了一个名为XFireService的接口和XFireServiceImpl这个实现接口的类。把相关的jar文件添加进项目里。

XFireService.java接口
package xfireservice;public interface XFireService {public String sayHello();}XFireServiceImpl.javapackage 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"?><beansxmlns="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框架写的。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表