继承CommandLineRunner接口,实现其run方法,run方法会在程序启动时,自动执行
public class FileSynchronize implements CommandLineRunner{ @Autowired private DataOperationService dataOperationService; private static FileSynchronize fileSynchronize; @PostConstruct public void init(){ fileSynchronize = this; }
//实现run方法 @Override public void run(String... args) throws Exception { //调用service层,操作数据库 fileSynchronize.dataOperationService.getXXX(); }
}