• Spring的application.xml文件加载监听器ApplicationListene


    在一个项目中有很多地方会用到一些常用但是不易变更的数据,比如中国股票市场的交易市场日,这些是可以确定,并且一般在今年中是不会改变的,所以可以将这些数据从数据库中加载到项目当中去,用spring管理这些bean时,可以使用spring文件加载监听器。例子:

    public class CalendarListener implements ApplicationListener<ContextRefreshedEvent> {  

      @Override

      public void onApplicationEvent(ContextRefreshedEvent ev) {
          if(ev.getApplicationContext().getParent() == null){
          Long startTime = System.currentTimeMillis();
        try {
          log.info("loading calendar time...start...");
          //需要预先加载的方法,此时spring已经所有的bean生成
          log.info("loading calendar time...end...");
        } catch (Exception e) {
          log.error("the calendar time is not loaded ,please check it!!!!!!",e);
        }
          log.info("loading china calendar time is :"+(System.currentTimeMillis()-startTime)+"ms");
        }
      }

    }

  • 相关阅读:
    C#学习历程(三)[基础概念]
    C#学习历程(二)[基础知识]
    C#学习历程(一)[基础概念]
    mvp和mvc的区别
    Java基础摘要(一)
    web前端概念摘要(一)
    Reflection_1
    后台管理_GMS_1
    模板收藏_1
    需求收藏_1
  • 原文地址:https://www.cnblogs.com/neruda/p/5327846.html
Copyright © 2020-2023  润新知