JAVA - 启动项目时做一些初始化

项目启动后做初始化操作

很多操作是想在项目启动后进行操作的,比如:

  1. 把数据库的敏感词写进内存中
  2. 同步redis数据
  3. 同步mysql数据

在启动类的存放位置如下:
在这里插入图片描述

@EnableScheduling
@SpringBootApplication
public class FristApplication {

    public static void main(String[] args) {
        SpringApplication.run(FristApplication.class, args);
    }

}

@Slf4j
@Component
class ApplicationRunnerImpl implements ApplicationRunner {

    @Autowired
    private TaskHanderComponent taskHanderComponent;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("||==================================开始初始化==================================||");
        log.info("||==================================执行任务==================================||");

		// 把数据库的敏感词写进内存中
		// 同步redis数据
//        taskHanderComponent.syncSensitive();
    }
}

猜你喜欢

转载自blog.csdn.net/m0_67393827/article/details/126722803