Spring Web应用程序:Post-DispatcherServlet初始化 [英] Spring Web Application: Post-DispatcherServlet initialization

查看:156
本文介绍了Spring Web应用程序:Post-DispatcherServlet初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring 3.2 DispatcherServlet.我正在寻找在初始化完成后 发生的初始化钩子;标准的Spring解决方案或servlet解决方案.有什么建议吗?

I am using Spring 3.2 DispatcherServlet. I am looking for an initialization hook that takes place after the DispatcherServlet initialization completes; either a standard Spring solution or servlet solution. Any suggestions?

作为参考,遵循Servlet启动后的最终日志记录语句.我希望我的初始化方法在configured successfully

As a point of reference, the final logging statements after servlet startup follow. I want my initialization method to execute right after the configured successfully log statement.

DEBUG o.s.w.s.DispatcherServlet - Published WebApplicationContext of servlet 'mySpringDispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.mySpringDispatcherServlet] 
INFO  o.s.w.s.DispatcherServlet - FrameworkServlet 'mySpringDispatcherServlet': initialization completed in 5000 ms   
DEBUG o.s.w.s.DispatcherServlet - Servlet 'mySpringDispatcherServlet' configured successfully 

根据我的研究,到目前为止,以下内容尚未达到预期的效果:

From my research, so far the following have not had the desired effect:

  1. 根据此答案扩展ContextLoaderListener/实施ServletContextListener.
  2. 每个WebApplicationInitializerrel ="nofollow noreferrer > javaoc .
  3. 我的豆子成功使用@PostConstruct;我正在寻找一个Servlet或容器级别的钩子,该钩子将在容器初始化和对bean进行后处理之后基本上执行.
  1. Extending ContextLoaderListener/implementing ServletContextListener per this answer.
  2. Implementing WebApplicationInitializer per the javaoc.
  3. My beans use @PostConstruct successfully; I'm looking for a Servlet or container level hook that will be executed essentially after the container initializes and post-processes the beans.

推荐答案

根本问题是我无法覆盖final方法

The root issue was that I couldn't override the final method HttpsServlet.init(). I found a nearby @Override-able method in DispatcherServlet.initWebApplicationContext that ensured my beans and context were fully initialized:


@Override
protected WebApplicationContext initWebApplicationContext()
{
    WebApplicationContext wac = super.initWebApplicationContext();

    // do stuff with initialized Foo beans via:
    // wac.getBean(Foo.class);

    return result;
}

这篇关于Spring Web应用程序:Post-DispatcherServlet初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆