Bootstrap servlet or Startup servlet


Sometime we need some services to be initialized when application gets started, Few application servers like weblogic provides handy feature where you can add startup classes when server gets started. There is a very nice and easy way where we can add bootstrap classes when application gets started. These classes we can use to init some services like logger,email agents, service agents, db factories etc. The below example will show how to do that using a simple servlet.

Step 1: write a simple servlet

public class StartupService extends HttpServlet{

private static final long serialVersionUID = 1L;

public void init(ServletConfig config) throws ServletException {

ADD Your logic here…
System.out.println(“Startup class initialized successfully”);


Step2:  Add the below mapping entry in web.xml


<!– Container/server will start the servlet when app gets start –>


Step 3: Start the server. you might will see “Starup class initialized successfully”.

R Vashi

2 thoughts on “Bootstrap servlet or Startup servlet

    1. ®V Post author

      Hi Ashish,

      Thanks for the query.

      A DbFactory defines all the interface methods that any client needs to implement to supply the instances of their XXXXDB interface implementations. This class is the single source for object creation. Application clients can set/get their particular choice of DbFactory implementation through the static methods of the DBManager class.

      or in other way you can also define a static Data Source object which points to one specific database using JNDI name.

      but all these rules require a static/singleton object which can make sure that it is global having single reference to the entire scope of the application. and in the startup servlets we have to just initialize those objects only once so that could be in the position to service the client request.

      Hope this helps, please let me know if you have any doubts.



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.