在 Spring Boot 中初始化 ServletContext 后如何创建 bean?

cri*_*sli 5 spring spring-boot spring-java-config

我有一个 bean,它实现了 ServletContextAware 和 BeanFactoryPostProcessor 接口。我需要在 ServletContext 完成初始化后将这个 bean 注册到 applicationContext 中,因为我使用了 servletContext 中的一些参数来初始化这个 bean。

我使用的是 Spring Boot,bean 名称是 SpringBeanProcessorServletAware。我已将其添加到配置 bean 中。

@Bean
public static SpringBeanProcessorServletAware springBeanProcessor() {
    SpringBeanProcessorServletAware p = new SpringBeanProcessorServletAware();
    return p;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是 bean 是在我的容器将servletContext设置为它之前创建的。然后我无法从servletContext获取参数。如何控制在我的servletContext完全创建后必须创建 bean ?