启动前运行:
@Slf4j
@Configuration
public class InitTaskRunner {
@Autowired
private XxxService xxxService;
@PostConstruct
public void init() {
//你的代码
}
}
启动后运行:
@Slf4j
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class InitTaskRunner implements ApplicationRunner {
@Autowired
private XxxService xxxService;
@Override
public void run(ApplicationArguments args) {
//你的代码
}
}