首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

XFire集成Spring配备

2012-09-09 
XFire集成Spring配置1.在项目的src下建了一个xfireservice的包,然后在这个包下建了一个名为XFireService的

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" 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" 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框架写的。

热点排行