cxf+web service(四)cxf+spring集成

客户端

public class Client {

	private Client(){}
	
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-client.xml");
        HelloWorld hw = (HelloWorld) context.getBean("client");
        String response = hw.zhuce("piter", "123456");
        System.out.println(response);
	}
}

 客户端配置文件,这里面配置代理工厂,地址,暴露的服务接口.这里也可以直接在客户端代码里面使用JaxWsProxyFactoryBean来发布

 <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.cxf.test.HelloWorld" factory-bean="clientFactory" factory-method="create" />

    <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="serviceClass" value="com.cxf.test.HelloWorld" />
        <property name="address" value="http://localhost:8080/cxf/ws/HelloWorld" />
    </bean>

 然后在spring.xml中加入接口的配置

<!-- Import Apache CXF Bean Definition -->
    <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"/>

    <jaxws:endpoint id="helloWorld" 
    	implementor="com.cxf.test.HelloWorldImpl" 
    	address="/HelloWorld"/>

 OK,最后在浏览器输入http://localhost:8080/cxf/ws,如下图,发布成功!



 运行客户端main方法,控制台输出,注册成功.

猜你喜欢

转载自mingnianshimanian.iteye.com/blog/2064441
今日推荐