CXF与Spring集成,配置webservice客户端,这里主要是调用上一章的webservice服务。
HelloWorld文件:
package com.flyfox.service;
<wbr></wbr>
import javax.jws.WebService;
<wbr></wbr>
@WebService
public interface HelloWorld {
<wbr><wbr><wbr></wbr></wbr></wbr> String sayHi(String text);
}
HelloWorldClient文件:
package com.flyfox.client;
<wbr></wbr>
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationC<wbr>ontext;</wbr>
<wbr></wbr>
import com.flyfox.service.HelloWorld;
<wbr></wbr>
public class HelloWorldClient {
<wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr> private static Logger logger = Logger.getLogger(HelloWorldClient.class);</wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr> public static void main(String[] args) {</wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> logger.info("####################################################111");</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> ApplicationContext context = new ClassPathXmlApplicationC<wbr>ontext("applicationContext-client.xml"); // your Spring ApplicationContext</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> logger.info("####################################################222");</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> HelloWorld client = (HelloWorld) context.getBean("client",HelloWorld.class);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> logger.info("####################################################333");</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> logger.info("client:"+client.sayHi("zhangsan"));</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr> }</wbr></wbr></wbr></wbr></wbr></wbr>
}
<wbr></wbr>
applicationContext-client.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
<wbr><wbr><wbr></wbr></wbr></wbr> xmlns:context="http://www.springframework.org/schema/context"
<wbr><wbr><wbr></wbr></wbr></wbr> xmlns:jaxws="http://cxf.apache.org/jaxws"
<wbr><wbr><wbr></wbr></wbr></wbr> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<wbr><wbr><wbr></wbr></wbr></wbr> xsi:schemaLocation="http://www.springframework.org/schema/beans
<wbr><wbr><wbr></wbr></wbr></wbr> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
<wbr><wbr><wbr></wbr></wbr></wbr> http://www.springframework.org/schema/context
<wbr><wbr><wbr></wbr></wbr></wbr> http://www.springframework.org/schema/context/spring-context-3.0.xsd
<wbr><wbr><wbr></wbr></wbr></wbr> http://cxf.apache.org/jaxws
<wbr><wbr><wbr></wbr></wbr></wbr> http://cxf.apache.org/schemas/jaxws.xsd">
<wbr><wbr><wbr></wbr></wbr></wbr>
<wbr><wbr><wbr></wbr></wbr></wbr> <import resource="classpath:META-INF/cxf/cxf.xml"/>
<wbr><wbr><wbr></wbr></wbr></wbr> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<wbr><wbr><wbr></wbr></wbr></wbr> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<wbr></wbr>
<wbr><wbr><wbr></wbr></wbr></wbr> <!--
<wbr><wbr><wbr></wbr></wbr></wbr> <bean id="client" class="com.flyfox.service.HelloWorld"
<wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr> factory-bean="clientFactory" factory-method="create" />
<wbr></wbr>
<wbr><wbr><wbr></wbr></wbr></wbr> <bean id="clientFactory"
<wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr> class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr> <property name="serviceClass" value="com.flyfox.service.HelloWorld" />
<wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr> <property name="address"
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> value="http://localhost:8080/CXFAndSpring/services/HelloWorld" />
<wbr><wbr><wbr></wbr></wbr></wbr> </bean>
<wbr></wbr><wbr><wbr> --></wbr></wbr>
<wbr><wbr><wbr></wbr></wbr></wbr> <jaxws:client id="client"<wbr></wbr> serviceClass="com.flyfox.service.HelloWorld"
<wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> address="http://localhost:8080/CXFAndSpring/services/HelloWorld"/>
<wbr><wbr><wbr></wbr></wbr></wbr>
</beans>