(转)Spring anotation实现xml中init方法功能
转自:http://www.mkyong.com/spring/spring-postconstruct-and-predestroy-example/
原文:Spring @PostConstruct And @PreDestroy Example
In Spring, you can either implements?InitializingBean and DisposableBean?interface or specify the?init-method and destroy-method?in bean configuration file for the initialization and destruction callback function. In this article, we show you how to use annotation?@PostConstruct?and?@PreDestroy?to do the same thing.
NoteA CustomerService bean with @PostConstruct and @PreDestroy annotation
Init method after properties are set : im property messagecom.mkyong.customer.services.CustomerService@47393f...INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@77158a: defining beans [customerService]; root of factory hierarchySpring Container is destroy! Customer clean up
The?initIt() method (@PostConstruct)?is called, after the message property is set, and the?cleanUp() method (@PreDestroy)?is call after the context.close();()