WebService-客户端简单测试-03

引入spring和cxf相关jar包

			<dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>4.3.21.RELEASE</version>
            </dependency>
            <!--因为需要测试 所以用到junit-->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <!-- 需要添加Spring相关最少jar包 -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>4.3.21.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>4.3.21.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>4.3.21.RELEASE</version>
            </dependency>
            <!-- 添加CXF相关jar包 -->
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-core</artifactId>
                <version>3.1.5</version>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxws</artifactId>
                <version>3.1.5</version>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http</artifactId>
                <version>3.1.5</version>
            </dependency>

打开apache-cxf-3.2.1下的bin 目录
在这里插入图片描述
在这里插入图片描述
输入cmd执行命令 :wsdl2java -p com.mr.service -client wsdl路径
在这里插入图片描述
执行成功生成文件
在这里插入图片描述
将生成的java文件导入到客户端指定目录下去
在这里插入图片描述
然后写一个测试类去测试是否可以调用成功

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "classpath:spring-cxf.xml")
public class Demo {

    @Autowired
    private Hello hello;

    @Test
    public void test1(){
        String s= hello.save("111", 22, 1);
        System.out.println(s);
    }
}

在Spring配置文件中添加<jaxws:client id="" serviceClass="" address="" ></jaxws:client>标签
id:代表接口的名称
serviceClass:接口在客户端的全路径
address:访问的wsdl路径

<?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">


    <jaxws:client id="hello" serviceClass="com.mr.cxf.client.Hello" address="http://localhost:8081/webservice/user?wsdl" ></jaxws:client>
</beans>

通过demo中的方法进行测试,成功后返回结果。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值