pom
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.5.0</version> <exclusions> <exclusion> <artifactId>asm</artifactId> <groupId>org.ow2.asm</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>javax.xml</groupId> <artifactId>jaxb-impl</artifactId> <version>2.1</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-xjc</artifactId> <version>2.3.0</version> </dependency>
java是核心包,javax的x是extension的意思,也就是扩展包。
client
package com.test; import org.apache.cxf.endpoint.Client; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; public class Test { public static void main(String[] args) throws Exception { JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(); Client client = factory.createClient("http://localhost:8000/order/api?wsdl"); //打印发出的消息 client.getInInterceptors().add(new LoggingInInterceptor()); //打印进入的消息 client.getOutInterceptors().add(new LoggingOutInterceptor()); Object[] res = client.invoke("yxxczyNoticeWorkOrder", "test"); System.out.println("Echo response: " + res[0]); } }
cxf不支持jdk11, 目前只支持jdk1.8, 官网有说明