spring怎么使用注解在初始化bean的时候init-method指定的方法

如题所述

用的三种指定特定操作的方法:
1、通过实现InitializingBean/DisposableBean 接口来定制初始化之后/销毁之前的操作方法;
2、通过<bean> 元素的 init-method/destroy-method属性指定初始化之后 /销毁之前调用的操作方法;
3、在指定方法上加上@PostConstruct或@PreDestroy注解来制定该方法是在初始化之后还是销毁之前调用。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-06-09
需要实现一个接口
org.springframework.beans.factory.InitializingBean;
这个这个接口有一个afterPropertiesSet 方法需要实现
然后配置bean 的时候指定 init-method="afterPropertiesSet" 如下示例
<bean id="config" class="com.chinapowerit.cmcc.config.Config" init-method="afterPropertiesSet">本回答被提问者和网友采纳