实现CommandLineRunner 接口,springboot在启动时会自动调用run方法。通过@Order注解可以指定执行顺序。

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(1)
public class InitExtraResource implements CommandLineRunner {

  @Autowired
  MetadataDubboService metadataDubboService;

  public static final Logger logger = LoggerFactory.getLogger(InitExtraResource.class);


  @Override
  public void run(String... strings) {
    logger.info("缓存数据库信息初始化开始。。。");
    metadataDubboService.refreshCache("ALL");//多线程实现,否则阻塞主线程
    logger.info("缓存数据库信息初始化成功!");
  }
}

 

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2021-10-08
  • 2022-12-23
  • 2023-03-27
  • 2021-11-03
  • 2022-12-23
猜你喜欢
  • 2021-07-04
  • 2021-11-19
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案