Chris Blackwell
Chris Blackwell

Reputation: 2178

override servlets load-on-startup locally

given a simple servlet in WEB-INF/web.xml like

<servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>app.MyServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

is it possible to override load-on-startup in my local dev environment so that the servlet is only loaded when first requested, without altering MyServlet class?

Altering web.xml is acceptable as long as the default is for the servlet to load when tomcat starts, could this be done with a context-param ?

I'm running tomcat 7.0.29

Upvotes: 1

Views: 319

Answers (1)

epoch
epoch

Reputation: 16595

Without modifying the web.xml? No you can not (to my knowledge). You can however remove the declaration completely and use the @WebServlet annotation, you can then modify loadOnStartup in the .java file directly.

@WebServlet(name="MyServlet", value="/MyServlet", loadOnStartup=1)
public class MyServlet extends HttpServlet {
    ...
}

Upvotes: 1

Related Questions