读书人

CXF6天系列第五天CXF+Spring配置

发布时间: 2012-09-21 15:47:26 作者: rapoo

CXF—六天系列—第五天—CXF+Spring配置客户端--HelloWorld!

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

HelloWorld文件:

packagecom.flyfox.service;

importjavax.jws.WebService;

@WebService

publicinterface 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:

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="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>

读书人网 >编程

热点推荐