CXF与Spring集成,配置webservice客户端,这里主要是调用上一章的webservice服务。

HelloWorld文件:

package com.flyfox.service;

 

import javax.jws.WebService;

 

@WebService

public interface HelloWorld {

    String sayHi(String text);

}

HelloWorldClient文件:

package com.flyfox.client;

 

import org.apache.log4j.Logger;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

 

import com.flyfox.service.HelloWorld;

 

public class HelloWorldClient {

 

       private static Logger logger = Logger.getLogger(HelloWorldClient.class);

      

       public static void main(String[] args) {

              logger.info("####################################################111");

              ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-client.xml"); // your Spring ApplicationContext

              logger.info("####################################################222");

              HelloWorld client = (HelloWorld) context.getBean("client",HelloWorld.class);

              logger.info("####################################################333");

              logger.info("client:"+client.sayHi("zhangsan"));

 

       }

}

 

applicationContext-client.xml:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:jaxws="http://cxf.apache.org/jaxws"

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

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-3.0.xsd

    http://cxf.apache.org/jaxws

    http://cxf.apache.org/schemas/jaxws.xsd">

   

    <import resource="classpath:META-INF/cxf/cxf.xml"/>

    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>

    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

 

    <!--

    <bean id="client" class="com.flyfox.service.HelloWorld"

       factory-bean="clientFactory" factory-method="create" />

 

    <bean id="clientFactory"

       class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">

       <property name="serviceClass" value="com.flyfox.service.HelloWorld" />

       <property name="address"

           value="http://localhost:8080/CXFAndSpring/services/HelloWorld" />

    </bean>

    -->

    <jaxws:client id="client"  serviceClass="com.flyfox.service.HelloWorld"

        address="http://localhost:8080/CXFAndSpring/services/HelloWorld"/>

   

</beans>

没有登录不能评论