zoukankan      html  css  js  c++  java
  • 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");
        }
      }

    }

  • 相关阅读:
    Entity Framework在Asp.net MVC中的实现One Context Per Request(转)
    Entity Framework中的Identity map和Unit of Work模式(转)
    hudi
    拉链表和流水表
    onedata
    window.top 踩坑前车之鉴
    识别RESTful API资源
    就是不想用if
    如何在面试中评估一个BA的能力
    Python逻辑运算结果的类型
  • 原文地址:https://www.cnblogs.com/neruda/p/5327846.html
Copyright © 2011-2022 走看看