You want a ServletContextListener, whose contextInitialized()
method is called when the webapp is initialized by the container, and which has access to the servlet context (i.e. the application scope)
How to write a Java method which will run when server startup? [closed]
-
19-07-2023 - |
Pregunta
I want to load some information from database, and share it in Application Scope
But I don't know where to write this method, can I initialize data in Application Scope when I start the server?
Solución
Otros consejos
You can go for load-on-startup
tells the servlet container to load the specified resource at server startup
<servlet>
<servlet-name>yourServletName</servlet-name>
<servlet-class>yourServletClass</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow