Lotus教程、Java教程、Java虚拟机、Java软件综合开发社区

Lotus、Domino、Java、C#、Web、数据库综合开发教程、资料社区

spring集成xfire-通过org.codehaus.xfire.spring.XFireSpringServlet集成



Published by admin on 03月 28, 2010

找了好几种spring集成xfire的资料,觉得最简单的一种就是通过org.codehaus.xfire.spring.XFireSpringServlet 接收来发布webservices .说它简单是因为都是用的 spring 和xfire 提供的类和文件 .具体过程:

服务器端:

1,首先配置 web.xml 文件:

<?xml version=“1.0″ encoding=“UTF-8″?>

<web-app version=“2.4″ xmlns=“http://java.sun.com/xml/ns/j2ee”

    xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

    xsi:schemaLocation=“http://java.sun.com/xml/ns/j2ee

    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>

    <context-param>

       <param-name>contextConfigLocation</param-name>

       <param-value>     /WEB-INF/applicationContext.xml,classpath:org/codehaus/xfire/spring/xfire.xml

       </param-value>

    </context-param>

    <listener>

       <listener-class>

           org.springframework.web.context.ContextLoaderListener

       </listener-class>

    </listener>

    <servlet>

       <servlet-name>xfire</servlet-name>

       <servlet-class>

           org.codehaus.xfire.spring.XFireSpringServlet

       </servlet-class>

    </servlet>

    <servlet-mapping>

       <servlet-name>xfire</servlet-name>

       <url-pattern>/services/*</url-pattern>

    </servlet-mapping>

</web-app>

告知启动后交给spring来管理 和 /services/* 交给XFireSpringServlet来处理.

2,完成接口和实现类.

package com.spring.ws;

 

public interface IMathServer {

    public int add(int x, int y);

}

package com.spring.ws;

public class MathServerImpl implements IMathServer {

    public int add(int x, int y) {

       return x + y;

    }

 

}

3,配置applicationContext.xml文件.

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”>
<beans>
<bean id=”addressingHander”
   class=”org.codehaus.xfire.addressing.AddressingInHandler“>
</bean>

<bean id=”mathServerImpl” class=”com.spring.ws.MathServerImpl”></bean>
<bean id=”servicesBean”
   class=”org.codehaus.xfire.spring.ServiceBean“>
   <property name=”serviceBean“>
    <ref bean=”mathServerImpl” />
   </property>
   <property name=”serviceClass“>
    <value>com.spring.ws.IMathServer</value>
   </property>
   <property name=”inHandlers“>
    <ref bean=”addressingHander” />
   </property>
</bean>
</beans>

4,url地址—http://localhost:8080/WebSx/services/IMathServer?wsdl

5,注意:

    (1)加包:

 

       (2)目录格式:

 

客户端:

1,配置文件:applicationContext.xml

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

<beans>
<bean id=”MathService
   class=”org.codehaus.xfire.spring.remoting.XFireClientFactoryBean“>
   <property name=”serviceClass“>
    <value>com.spring.ws.IMathServer</value>
   </property>
   <property name=”wsdlDocumentUrl“>
    <value>
    http://localhost:8080/WebSx/services/IMathServer?wsdl
    </value>
   </property>
</bean>
</beans>

2,测试类:

package com;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.spring.ws.IMathServer;

public class Text {

public static void main(String[] args) {
   ApplicationContext ctx = new ClassPathXmlApplicationContext(
     “applicationContext.xml”);
   IMathServer math = (IMathServer) ctx.getBean(”MathService“);
   System.out.println(math.add(1, 2));
}
}


下一篇文章:Web Service-简介 »

【版权说明】:本网页上有部分内容来源于网上收集,但不能保证资料的完整性和准确性,仅提供参考和学习。如有侵权请立即通知我们,我们将立即删除,谢谢合作!

Comments are closed.