我有一个spring boot应用程序,我需要在启动时调用服务(一个休息终点)。
答案 0 :(得分:2)
RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject("http://www.example.com/api/resource", String.class);
您可以使用这个方便的界面在应用程序启动时执行您想要的任何任务。
要调用REST端点,您可以使用 RestTemplate
{{1}}
如果您使用与JSON响应匹配的字段构建POJO,RestTemplate将在Jackson的帮助下自动映射它们。有关更多详细信息,请参阅文档。
答案 1 :(得分:1)
我建议您查看@PostConstruct
注释。
答案 2 :(得分:0)
我使用和实施ApplicationRunner
答案 3 :(得分:0)
您还可以将应用挂钩到ApplicationReadyEvent
或Spring触发的其他事件: