三种springboot启动时加载方式
三种springboot启动时加载方式
一个注解,两个接口,常用于数据预热:
`@PostConstruct`
`implements CommandLineRunner`
`implements ApplicationRunner`
@Slf4j
@EnableAsync
@SpringBootApplication
public class ApiApplication extends SpringBootServletInitializer implements CommandLineRunner {
@Autowired
private RiskLevelService riskLevelService;
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ApiApplication.class);
}
//implements CommandLineRunner
@Override
public void run(String... args) throws Exception {
log.info("假装在预热");
}
//@PostConstruct
//public void preLoadCache() {
// log.info("假装在预热");
//}
//implements ApplicationRunner
//@Override
//public void run(ApplicationArguments args) throws Exception {
// log.info("假装在预热");
//}
}