I am using the JerseyServletContainer mechanism in order to deploy my REST web services. The configuration in the web.xml looks like below:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.myservlet.classes
</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
What i would like to achieve is that my REST Resource class to be constructed before the first HTTP call to the REST service.
At the moment, even though i have set
<load-on-startup>0</load-on-startup>
seems like the actual class' constructor is called by Jersey's ServletContainer only when a HTTP request is firstly made to that resource.
Is there a way to achieve that?
I need to add that, at the moment i have just added a ServletContextListener which makes a HTTP call to itself. But i would like to avoid that hacky way.
Any help/advice much appreciated?
EDIT: I need to add that i am using @Singleton annotation on my Resource class as i need only one instance throughout the application