Tomcat after Startup Event with spring

前端 未结 3 1078
情书的邮戳
情书的邮戳 2020-12-19 19:47

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 re

3条回答
  •  不思量自难忘°
    2020-12-19 20:20

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

    • 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:

    • you start spring via a listener (and not with a servlet)
    • you configure hibernate within spring

    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

提交回复
热议问题