1、openapi服务启动时去调用天气接口获取数据

This commit is contained in:
xjs 2022-04-19 11:59:15 +08:00
parent 2f12b4535b
commit b0158967d5
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package com.xjs.common.run;
import com.xjs.weather.service.WeatherService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* 服务启动时执行类
* @author xiejs
* @since 2022-04-19
*/
@Component
@Log4j2
public class ApplicationRunnerImpl implements ApplicationRunner {
@Autowired
private WeatherService weatherService;
@Override
public void run(ApplicationArguments args) {
log.info("获取天气数据中...");
weatherService.saveNowWeather();
weatherService.cacheForecastWeather();
log.info("获取天气数据完成...");
}
}