How to call a method on application load

How to call a method on application load

Imagine that you need to do some work just before or a little after an application starts. It might be to prepare some configuration or to start some background services. There is a very simple solution to call some java method on an ADF Application boot time – It’s a servlet with “Load on application start” option.

Prepare Servlet class

Create class BootstrapServlet class which extends javax.servlet.http.HttpServlet.


Override the init method and paste your code. In my case is just to print some message.

Register in web.xml

Register Booststrap servlet in web.xml  file(1,2,3,4,5). Make sure the load order is right. In my case I changed(6) faces servlet order to 10 and BooststrapServlet to 5.


Full web.xml content:


Run application. As you can see the BootstrapServlet started before faces servlet.


The use cases (examples)

  • You can start some background thread (service) in the Servlet init method which periodically do some work – For instance: asynchronous file processing.
  • You can prepare some configuration.
  • You can send a notification about application state.

Leave a Reply

Notify of
Close Menu