Reputation: 103597
I have servlet in my web.xml but i don't want my application to load it, one would think that if we don't want that servlet to load then what is the purpose of putting it there, actually I need to have it in web.xml because am deploying two instances of application and on one instance I need to have that servlet and on another I do not want to have it and I'm using only one web.xml
, am not sure how this can be done.
Here is my web.xml
:
<servlet>
<servlet-name>StartServlet</servlet-name>
<servlet-class>com.web.startServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
I cannot put -ve
value because then container would invoke this servlet randomly, kindly correct me here and advise of an proper way to do it.
Upvotes: 2
Views: 918
Reputation: 18224
You can disable the Servlet (which means that it will not be reachable through defined url-pattern mapping) by using enabled
element in web.xml.
Servlets 3.0 specification in Chapter 8.2.3 Assembling the descriptor from web.xml, web-fragment.xml and annotations says:
(...) 3. If a servlet is disabled using the enabled element introduced in the web.xml then the servlet will not be available at the url-pattern specified for the servlet. (...)
The enabled
element is defined in XML Schema here and can be found as a child element of the <servlet>
element.
Upvotes: 1
Reputation: 4824
<load-on-startup>
allows you to configure lazy-loading. By default the servlet is loaded only when it is accessed (by its url-pattern). You can set it to be loaded on startup instead.
That said, if you set the servlet that isn't supposed to load to only load on request, and then use a load balancer to ensure that whatever URL would hit that server hits the other one instead, you'd probably be good to go.
+1 to Bozho. His answer is a great place to start.
Upvotes: 0
Reputation: 597402
<load-on-startup>
allows you to configure lazy-loading. By default the servlet is loaded only when it is accessed (by its url-pattern). You can set it to be loaded on startup instead.
Upvotes: 1