InitializingBean

神奇的InitializingBean

 

api里这样写

 

org.springframework.beans.factory

public interface InitializingBean

Interface to be implemented by beans that need to react once all their properties have been set by a BeanFactory: for example, to perform custom initialization, or merely to check that all mandatory properties have been set.

An alternative to implementing InitializingBean is specifying a custom init-method, for example in an XML bean definition. For a list of all bean lifecycle methods, see the BeanFactory javadocs.

 

一旦他们所有的属性被BeanFactory设置就需要起作用的将被beans执行的接口:例如,执行用户自定义初始化,或仅仅是检查所有托管的属性已经被设置。

 

只有一个方法:

afterPropertiesSet

void afterPropertiesSet()  throws Exception
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

 

Throws:
Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.

 主要是实现这个接口,在这个实现的方法里可以执行一些初始化工作

 

实现这个接口的类太多了,可以看在线文档http://static.springsource.org/spring/docs/2.0.x/api/index.html

 

你可能感兴趣的:(spring,html,bean,xml,工作)