Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

java - Tomcat after Startup Event with spring

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...