用spring的 InitializingBean 的 afterPropertiesSet 来初始化

void afterPropertiesSet() throws Exception;

这个方法将在所有的属性被初始化后调用。

但是会在init前调用。

但是主要的是如果是延迟加载的话,则马上执行。

所以可以在类上加上注解:

import org.springframework.context.annotation.Lazy;

@Lazy(false)

这样spring容器初始化的时候afterPropertiesSet就会被调用。

posted @ 2019-08-08 16:26  飘飘雪  阅读(316)  评论(0编辑  收藏  举报