首先新建一个webservice工程,添加以下内容至web.xml:
<!-- spring 配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</param-value> </context-param> <!-- spring 配置文件监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 字符码filter配置 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <!-- 字节码filter映射 --> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- webserves配置 --> <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> <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>/service/*</url-pattern> </servlet-mapping>
然后再WEB-INF下新建一个xfire-servlet.xml(名字对应为web.xml里配置的servlet名称,eg:xxx-servlet.xml):
<?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 class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/UsrInfoForBossService"> <ref bean="usrInfoServiceXf"/> </entry> </map> </property> </bean> <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true"> <property name="serviceFactory"> <ref bean="xfire.serviceFactory"/> </property> <property name="xfire"> <ref bean="xfire"/> </property> </bean> <bean id="usrInfoServiceXf" parent="baseWebService"> <property name="serviceBean"> <ref bean="usrInfoService"/> </property> <property name="serviceClass"> <value>com.xxx.service.UsrInfoForBossService</value> </property> </bean> </beans>