weixin_38290853
weixin_38290853
2017-06-23 06:58

SpringBoot中,定时任务:httpclient调用WebService。

  • spring

Springboot框架中,httpClient调用WebService类中的main方法,怎么改为项目启动,就自动执行这个方法?
@Sch@Scheduled(cron = "*/10 * * * * ?"):
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
DynamicHttpclientCall dynamicHttpclientCall = new DynamicHttpclientCall(
"http://service.example.com/", "getUser",
"http://localhost:8080/webservice/userService?wsdl");
Map patameterMap = new HashMap();
patameterMap.put("id", "1");
String soapRequestData = dynamicHttpclientCall.buildRequestData(patameterMap);
System.out.println(soapRequestData);
int statusCode = dynamicHttpclientCall.invoke(patameterMap);
String returnJson = "";
if(statusCode == 200) {
System.out.println("调用成功!");
System.out.println(dynamicHttpclientCall.soapResponseData);
}
else {
System.out.println("调用失败!错误码:" + statusCode);
}
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答