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);
}
}
SpringBoot中,定时任务:httpclient调用WebService。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答
- 三呆子 2017-06-23 08:00关注
1.写一个class 然后 implements ApplicationListener
2.给这个class加上@Configuration注解 (import org.springframework.context.annotation.Configuration)
3.你再启动main试试,success解决 无用评论 打赏 举报