spring boot 启动监听获取ApplicationContext上下文

如果需要获取ApringApplication上下文,可以实现ApplicationContextAware接口,重写setApplicationContext方法;

@Component
public class ApplicationAware implements ApplicationContextAware {
    private static ApplicationContext __applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(".....ApplicationAware");
        __applicationContext = applicationContext;
    }
}

以上取到的ApplicationContext就是当前运行的ApplicationContext上下文!

 

你可能感兴趣的:(spring,boot)