1. 添加如下依赖:
<!-- CXF webservice -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.1.11</version>
</dependency>
<!-- CXF webservice -->
2. 通过CXF的JaxWsDynamicClientFactory来调用接口:
//在一个方法中连续调用多次WebService接口,每次调用前需要重置上下文
ClassLoader cl = Thread.currentThread().getContextClassLoader();
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
Client client = clientFactory.createClient("http://192.168.1.21:8080/UserCenter/webservice/userLoginService?wsdl");
Object[] result = client.invoke("login", "coffee01", "123456"); // 设置调用的方法login 参数1,参数2
System.out.println(result[0]); // 输出返回结果
Thread.currentThread().setContextClassLoader(cl);
Client clientB = dcf.createClient("http://192.168.1.66:8080/groupClass/ws/getSayGoodByeService?wsdl");
Object[] resultB = clientB.invoke("sayGoodBye", "Joker");
System.out.println("resultB===>" + resultB[0]);