zoukankan      html  css  js  c++  java
  • apache cxf笔记之Spring客户端访问和调用webservice服务

    继续上次的spring服务的问题,这边介绍一种spring配置客户端的方法。

    1、src目录下新建client-beans.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd">
        
        <!-- 方式一:基于spring的jaxws -->
        <!-- <jaxws:client
            id="client" serviceClass="demo.cxf.helloworld.HelloWorld" 
            address="http://localhost:8080/HelloWorld"/> -->
            
        <!-- 方式二:基于cxf的JaxWsProxyFactoryBean -->
        <bean id="client" class="demo.cxf.helloworld.client.ClientSpring"
            factory-method="create" factory-bean="clientFactory"/>
        <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
            <property name="serviceClass" value="demo.cxf.helloworld.HelloWorld"/>
            <property name="address" value="http://localhost:8080/HelloWorld"/>
        </bean>
    </beans>


    2、客户端调用类:ClientSpring

    package demo.cxf.helloworld.client;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import demo.cxf.helloworld.HelloWorld;
    
    public class ClientSpring {
    
    	public static void main(String[] args) {
    		System.out.println("Start client.....");
    		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
    				new String[] { "classpath:client-beans.xml" });
    		HelloWorld helloWorld = (HelloWorld) context.getBean("client");
    		
    		System.out.println(helloWorld.sayHello("Jobs"));
    		System.exit(0);
    	}
    }
    

    3、先启动前面所讲的spring服务

    4、运行客户端程序Run as JavaApplication


    其实还有代码直接实现的,不用配置文件的,这边就不介绍了,跟配置文件类似的。实际开发中还是主要用到XML配置文件的。

  • 相关阅读:
    国内使用kubeadm部署kubernetes的完整流程
    Paxos协议笔记
    【LLVM笔记】0x00 初识LLVM 链接类型
    TLS 1.0协议
    风险指针(Hazard Pointer) 内存空间共享模型
    LRU算法
    从.git文件夹探析git实现原理
    Python爬虫与一汽项目【三】爬取中国五矿集团采购平台
    Python爬虫与一汽项目【二】爬取中国东方电气集中采购平台
    Python爬虫与一汽项目【一】爬取中海油,邮政,国家电网问题总结
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3187015.html
Copyright © 2011-2022 走看看