Can some code run when we first deploy a WAR file?

后端 未结 3 2239
星月不相逢
星月不相逢 2021-02-14 19:56

Is there any method or API that I can use so that whenever I deploy a new WAR file, a part of code should execute or perhaps when Tomcat starts, the respective servlet should s

3条回答
  •  心在旅途
    2021-02-14 20:51

    You can include a "ContextListener" in web.xml. An instance of this class would be created when Webb application WAR is about to be deployed/started.

    This code can start a thread that would keep running till app is deployed.

    Example : http://www.javafaq.nu/java-example-code-233.html

提交回复
热议问题