How to create a bean after ServletContext initialized in Spring Boot?

风格不统一 提交于 2019-12-23 13:07:53

问题


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?

来源:https://stackoverflow.com/questions/34525337/how-to-create-a-bean-after-servletcontext-initialized-in-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!