springboot提供cxf接口调用和postman调用
@WebService(name="GetWeatherService")
public interface GetWeatherService {
@WebMethod
@WebResult(name = "String",targetNamespace = "")
String getWeatherByCity(@WebParam(name ="cityCode") String cityCode,@WebParam(name ="cityName") String cityName);
}
@Service
@WebService(serviceName = "GetWeatherService" ,
targetNamespace = "http://WebService.service.xx.xx.xx.com/", //interface的报名倒叙
endpointInterface = "com.xx.xx.xx.service.WebService.GetWeatherService") //interface的位置
@Component
public class GetWeatherServiceImpl implements GetWeatherService{
@Override
public String getWeatherByCity(String cityCode,String cityName) {
System.err.println("xxxxxxxxxxxxxxxxxx");
System.err.println(cityCode+"-----"+cityName);
return "上海:020;天气:多云转晴";
}
}
@Configuration
public class CxfConfig {
@Autowired
private GetWeatherService getWeatherService;
//所有cxf请求带/Web/ 前缀
@Bean
public ServletRegistrationBean newServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/Web/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
// @Bean
// public Endpoint endpoint() {
// EndpointImpl endpoint = new EndpointImpl(springBus(), getWeatherService);
// endpoint.publish("/getWeatherService");
// return endpoint;
// }
//
@Bean
public Endpoint another_endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), getWeatherService);
endpoint.publish("/common"); //发布地址
return endpoint;
}
postman测试
post请求
Content-Type:text/xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
//方法名 包含参数
<ns2:getWeatherByCity xmlns:ns2="http://WebService.service.xx.xx.xx.com/">//包名倒叙
<cityCode>cityCode</cityCode>//参数
<cityName>cityName</cityName>
</ns2:getWeatherByCity>
</soap:Body>
</soap:Envelope>