1.pom
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>apache-cxf</artifactId>
<version>3.1.6</version>
</dependency>
2.接口发布
2.1.接口
package com.qin.soap.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface InterfaceService {
@WebMethod
public String isConnect();
}
2.2.接口实现
package com.qin.soap.service.impl;
import javax.jws.WebService;
@WebService(targetNamespace = "http://service.soap.qin.com/", endpointInterface = "com.qin.soap.service.InterfaceService")
public class InterfaceServiceImpl implements InterfaceService {
@Override
public String isConnect() {
return "success";
}
}
2.3.主启动类注入
@Bean
public ServletRegistrationBean servletRegistrationBean() {
return new ServletRegistrationBean(new CXFServlet(), "/services/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public InterfaceService interfaceService() {
return new InterfaceServiceImpl();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), interfaceService());
endpoint.publish("/InterfaceService");
return endpoint;
}
3.服务调用
public static void main(String[] args) throws Exception {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:ip/contextPath/services/InterfaceService?wsdl");
Object[] objs =client.invoke("isConnect",null);
System.out.println(objs[0]);
}