启动事件后的Tomcat与spring [英] Tomcat after Startup Event with spring

查看:232
本文介绍了启动事件后的Tomcat与spring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数我想在tomcat启动后直接执行并成功加载其所有属性。我不想使用ServletContextListener,因为这需要在tomcat启动之前启动该函数。有人可以建议怎么做吗?

I have a function I want to execute straight after tomcat has started and loaded all its attributes successfully. I don't want to use ServletContextListener as this will require the function to start before tomcat starts. Can someone suggest how to go about this?

推荐答案

ServletContextListener.contextInitialized(..) 是在为给定应用程序初始化所有servlet和过滤器之后调用的方法。

ServletContextListener.contextInitialized(..) is the method that is called after all servlets and filters have initialized for a given application.


  • 如果有多个 ServletContextListener s,如果有多个应用程序(因此有多个上下文),其中一些应用程序启动了其中一些(逻辑上)

  • 在其他人之前。

  • if there are multiple ServletContextListeners, some of them are called before the others (logically)
  • if there are multiple applications (hence multiple contexts) some of them are started before others.

更新我现在假设您的设置,但您没有分享它:

Update I will now assume your setup, although you didn't share it:


  • 你通过监听器开始弹簧(而不是servlet)

  • 你在春天配置hibernate

在这种情况下,你有两个选择ns:

In that case, you have two options:

  • define your ServletContextListener after the one for spring in web.xml, thus guaranteeing it will be invoked after it
  • use spring's lifecycle processor

这篇关于启动事件后的Tomcat与spring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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