Is there a way to run a method/class only on Tomcat/Wildfly/Glassfish startup?

后端 未结 3 1055
遥遥无期
遥遥无期 2020-11-29 20:50

I need to remove temp files on Tomcat startup, the pass to a folder which contains temp files is in applicationContext.xml.

Is there a way to run a method/class only

3条回答
  •  天命终不由人
    2020-11-29 21:26

    I'm sure there must be a better way to do it as part of the container's lifecycle (edit: Hank has the answer - I was wondering why he was suggesting a SessonListener before I answered), but you could create a Servlet which has no other purpose than to perform one-time actions when the server is started:

    
      Does stuff on container startup
      StartupServlet
      StartupServlet
      com.foo.bar.servlets.StartupServlet
      1
     
    

提交回复
热议问题