首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

(转)Spring anotation兑现xml中init方法功能

2012-12-21 
(转)Springanotation实现xml中init方法功能转自:http://www.mkyong.com/spring/spring-postconstruct-and-

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

热点排行