1.在项目中引入CXF的依赖
<!-- apache-CXF-frontend -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${apache-cxf.frontend.version}</version>
</dependency>
<!-- apache-cxf-transports -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${apache-cxf-transports.version}</version>
</dependency>
2.使用wsimport -s . http://localhost/8081/service/customerService?wsdl解析wsdl文件生成本地代码,只需要接口文件和实体类
3.在spring的配置文件中注册cxf的客户端代理对象
<!--注册CXF的客户端代理-->
<jaxws:client id="crmClient"
serviceClass="com.jujung.bos.webservice.CustomerService"
address="http://localhost:8081/service/customerService"/>
4.测试代码
/**
* @author Jujung_Zheng
* @create 2019-01-04 12:21
*/
public class CXFTest {
@Test
public void TestCXFCall() throws Exception {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("classpath:spring/applicationContext-service.xml");
CustomerService bean = context.getBean(CustomerService.class);
List<Customer> customerList = bean.getCustomerList();
}
}
测试结果
成功调用并返回结果