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

后端 未结 3 2137
滥情空心
滥情空心 2021-02-14 20:10

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

    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

提交回复
热议问题