java-ApplicationContextAware接口

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 {
}

}


版权声明:本文为u012383818原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。