继续上次的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配置文件的。

apache cxf笔记之Spring客户端访问和调用webservice服务的更多相关文章

  1. Spring Boot 使用 JAX-WS 调用 WebService 服务

    除了 CXF 我们还可以使用 Spring Boot 自身默认的组件 JAX-WS 来实现 WebService 的调用. 本项目源码 github 下载 1 新建 Spring Boot Maven ...

  2. Spring Boot 使用 CXF 调用 WebService 服务

    上一张我们讲到 Spring Boot 开发 WebService 服务,本章研究基于 CXF 调用 WebService.另外本来想写一篇 xfire 作为 client 端来调用 webservi ...

  3. cxf 调用 webservice服务时传递 服务器验证需要的用户名密码

    cxf通过wsdl2java生成客户端调用webservice时,如果服务器端需要通过用户名和密码验证,则客户端必须传递验证所必须的用户名和密码,刚开始想通过url传递用户名和密码,于是在wsdl文件 ...

  4. winform客户端程序第一次调用webservice方法很慢的解决方法

    .net2.0的winform客户端最常用的与服务端通信方式是通过webservice,最近在用dottrace对客户端做性能测试的时候发现,客户端程序启动以后,第一次调用某一个webservice的 ...

  5. C#开发WEBService服务 C++开发客户端调用WEBService服务

    编写WEBService服务端应用程序并部署 http://blog.csdn.net/u011835515/article/details/47615425 编写调用WEBService的C++客户 ...

  6. Apache cxf暴露接口以及客户端调用之WebService初步理解

    在我们真实的项目中,经常会调用别人提供给我们的接口,或者在自己的团队中, restful风格的前后端分离也经常会提供一个后端接口暴露出去供app,或者.net/C/C++程序员去调用,此时就需要使用到 ...

  7. C++客户端通过gSOAP调用WebService

    webService三要素: SOAP(Simple Object Access Protocol).WSDL(WebServicesDescriptionLanguage).UDDI(Univers ...

  8. Spring与apache CXF结合实例

    本文的前提是已经有一个Spring的项目,在此基础上如何跟apache CXF进行结合,开发出WebService服务和调用WebService服务. 1.开发WebService   1.引入jar ...

  9. 基于Apache CXF的Web Service服务端/客户端

    转自:https://www.aliyun.com/zixun/wenji/1263190.html CXF服务端: package com.sean.server; import javax.jws ...

随机推荐

  1. Linux Mysql 权限相关信息 来源于网络

    查看用户权限 show grants for 你的用户 比如: show grants for root@’localhost’; mysql> use mysql; Database chan ...

  2. .net的页面在大并发下出现503错误

    .net的页面在大并发下偶尔出现503错误 我们开发了一个回调页面,由一个工具负责调用,由于压力非常大,回调页面通过6台服务器负载均衡的: 最近业务系统又再次扩容,回调页面压力成倍增加,在高峰时间段偶 ...

  3. wpf的datagrid和winform的datagridview刷新

    DataGrid的数据源的加载需要大量IO操作,不可能等数据全部读取之后才显示到UI上.由于对WPF数据绑定不很熟悉,对ObserveCollection等内容没有太多时间去研究,只能用一些取巧的办法 ...

  4. JQuery的两个each方法的注意点

    Jquery官网上两个each用法: http://api.jquery.com/jQuery.each/ http://api.jquery.com/each/ 使用时注意点 <!DOCTYP ...

  5. SpringMVC 国际化

    SpringMVC学习系列(8) 之 国际化 在系列(7)中我们讲了数据的格式化显示,Spring在做格式化展示的时候已经做了国际化处理,那么如何将我们网站的其它内容(如菜单.标题等)做国际化处理呢? ...

  6. SQLSERVER数据库学习总结七(视图,索引)

    --视图的主意点:不能和表的名称相同,如果某一列为函数,表达式,常量或者与来自多张表的列名相同,必须为列定义名称,不能在试图上创建索引 if exists(select 1 from sys.syso ...

  7. 表达式树解析"框架"

    干货!表达式树解析"框架"(2)   为了过个好年,我还是赶快把这篇完成了吧 声明 本文内容需要有一定基础的开发人员才可轻松阅读,如果有难以理解的地方可以跟帖询问,但我也不一定能回 ...

  8. script —— 终端里的记录器

    当 你在终端或者控制台工作时,你可能想要记录在终端中所做的一切.这些记录可以用来当作史料,保存终端所发生的一切.比如说,你和一些Linux管理员们同 时管理着相同的机器,或者你让某人远程登陆到了你的服 ...

  9. 【IOS开发】搜索和排序(好友列表,通讯录的实现,searchbar)

    一.效果图: 二.概述 实现一个好友列表,可以分为男女两个选项,并且实现搜索和排序功能.我的数据是放在plist文件中. 三.代码简述 代码结构如图,首先自定义一个Cell. cell.h #impo ...

  10. [转]Whirlwind Tour of ARM Assembly

    ref:http://www.coranac.com/tonc/text/asm.htm 23.1. Introduction Very broadly speaking, you can divid ...