美文网首页
Spring的@PostConstruct标签详解

Spring的@PostConstruct标签详解

作者: 秋名山车神_f776 | 来源:发表于2018-03-19 14:25 被阅读0次

@PostContruct是spring框架的注解,在方法上加该注解会在项目启动的时候执行该方法,也可以理解为在spring容器初始化的时候执行该方法。

/**
  * 功能说明:启动项目 将字典放入缓存中
  */
@PostConstruct
public void SynDictionary() {

      //设置日期格式
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
      // new Date()为获取当前系统时间
      System.out.println("字典缓存开始:"+df.format(new Date()));

      List<Dic> dicList = dicmanagedao.getDicInfo();

      for (Dic dic:dicList) {
          EHCacheMonitFile.saveCatch("maxvalue_dic_" + dic.getDictype().getCode() + "_" + 
                                     dic.getCode(),  dic.getName());
       }

      System.out.println("字典缓存结束:"+df.format(new Date()));// new Date()为获取当前系统时间

}

相关文章

网友评论

      本文标题:Spring的@PostConstruct标签详解

      本文链接:https://www.haomeiwen.com/subject/ztcpqftx.html