How to create a bean after ServletContext initiali

2019-06-27 22:44发布

问题:

I have a bean, which implements ServletContextAware and BeanFactoryPostProcessor interfaces. I need this this bean register into the applicationContext after the ServletContext finished initialization, because I use some parameters in the servletContext to init this bean.

I am using the Spring Boot, the bean name is SpringBeanProcessorServletAware. I have add it into a configuration bean.

@Bean
public static SpringBeanProcessorServletAware springBeanProcessor() {
    SpringBeanProcessorServletAware p = new SpringBeanProcessorServletAware();
    return p;
}

My issue is that the bean is created before my container set servletContext to it. Then I can't get the parameters from the servletContext. How to control that the bean must be created after my servletContext has been created completely?