读书人

(转)Spring anotation兑现xml中ini

发布时间: 2012-12-21 12:03:49 作者: rapoo

(转)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.

Note
The?@PostConstruct?and?@PreDestroy?annotation are not belong to Spring, it’s located in the J2ee library common-annotations.jar.

@PostConstruct and @PreDestroy

A 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();()

读书人网 >XML SOAP

热点推荐