1.在具体Bean的实例化过程中,@PostConstruct注解的方法,会在构造方法之后,init方法之前进行调用
2.在项目中@PostConstruct主要应用场景是在初始化Servlet时加载一些缓存数据等

举个例子,使用@PostConstruct注解:

Class ServiceA{
    private Map<String, String> initMap;    

    //在这里加载一些缓存数据
    @PostConstruct
    public void init() {
        initMap = new HashMap<>(3);
        initMap.put("A","the a");
        initMap.put("B","the b");
        initMap.put("C","the c");
    }

}

  

posted on 2018-08-14 11:31  dbave  阅读(253)  评论(0编辑  收藏  举报