javaweb-servicesxfire

Disable @Webservice loading during start up


How to disable @Webservice loading during start up to save some loading time in xfire?

I have a bunch of services with @Webservice annotation. They are all being loaded during the startup and causing a slow startup. I don't want to load these if I test non-services in dev instance. I am wondering if there is a way to disable this by setting system property or something .


Solution

  • Sure, in your web.xml, where you configure the xfire servlet:

    <servlet>
        <servlet-name>xfire</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>-1</load-on-startup>
    </servlet>
    

    A negative value for load-on-startup means the servlet is only initialized when the container 'feels like it', and for most containers, this means when the first request comes in.

    From the servlet specification:

    The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive 128 integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.

    So consult the documentation for your web container to make sure this has the desired effect in your case.