1、写一个接口
属性解释:
targetNamespace:命名空间
@WebParam.name: 参数名称
@WebService(name = "PassBackService", targetNamespace = "http://hr.service.webservice.api.controller.web.ruoyi.com")
public interface PassBackService {
@WebMethod
String packBackOutPersonData(@WebParam(
name = "xmlString",
targetNamespace = "http://hr.service.webservice.api.controller.web.ruoyi.com"
) String xmlString);
}
2、写一个实现类
属性解释:
serviceName : 服务名称
targetNamespace:命名空间
endpointInterface:指向的接口
@Service
@WebService(serviceName = "PassBackService", targetNamespace = "http://hr.service.webservice.api.controller.web.ruoyi.com",
endpointInterface = "com.ruoyi.web.controller.api.webservice.service.hc.PassBackService"
)
public class PassBackServiceImpl implements PassBackService {
@Override
public String packBackOutPersonData(String xmlString){
}
}
3、发布接口
注意:
ServletRegistrationBean:配置接口访问路径前缀
Bus.DEFAULT_BUS_ID:唯一且必须
EndpointImpl:入参是待发布接口
publish:配置接口统一访问路径
@Configuration
public class WebServiceConfig {
@Autowired
private PassBackService passBackService;
/**
* 注入servlet bean name不能dispatcherServlet 否则会覆盖dispatcherServlet
* @return
*/
@Bean(name = "passBackServlet")
public ServletRegistrationBean cxfServlet() {
return new ServletRegistrationBean(new CXFServlet(),"/webservice/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
/**
* 注册passBackService接口到webservice服务
* @return
*/
@Bean(name = "passBackService")
public Endpoint syncPersonProjectEndpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), passBackService);
endpoint.publish("/passBack");
Map<String,Object> propertyMap = new HashMap<>();
propertyMap.put("autoRewriteSoapAddress",true);
endpoint.setProperties(propertyMap);
return endpoint;
}
}
4、调用接口
项目中如果使用sercurity安全认证,记得加白名单
http:localhost:8080/webservice/passBack?wsdl