How to initialize a web application?

My web application will be deployed as a WAR package in a Jetty instance. Before executing queries, you need to do a lot of caching. How can I call the caching method before anything else? is static void main () in the web application standard?

+4
source share
1 answer

The standard (old) way is to encode a servlet that takes care of initialization in its init() method. You force it to initialize when the application starts, adding a load-on-startup positive value to web.xml

  <servlet> <servlet-name>myinit</servlet-name> <servlet-class>com.example.MyInitServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> 

Today, a more common is a bean container such as Spring, which takes care of such things (instance objects, preloading cached data, etc.).

Note: this recipe is for webapps in general, not Jetty.

+4
source

Source: https://habr.com/ru/post/1308955/


All Articles