java-ApplicationContextAware接口

来源:互联网 发布:电脑上的c语言编程软件 编辑:程序博客网 时间:2024/06/01 11:35

1、spring配置文件配置信息:

<beans:bean id="StartupListen" class="com.armitage.common.controller.StartupListen"></beans:bean>

2、加载Spring配置文件时,如果Spring配置文件中所定义的类StartupListen实现了ApplicationContextAware 接口,那么在加载Spring配置文件时,会自动调用ApplicationContextAware 接口中的setApplicationContext方法,获得ApplicationContext对象。

前提必须在Spring配置文件中指定该类

<beans:bean id="StartupListen" class="com.armitage.common.controller.StartupListen"></beans:bean>


3、StartupListen代码:

public class StartupListen implements ApplicationContextAware {

private Log log = LogFactory.getLog(getClass());

public void setApplicationContext(ApplicationContext applicationContext)
   throws BeansException {
}

}