aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes JAX-RS resource lifecycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "JAX-RS resource lifecycle" Watch "JAX-RS resource lifecycle" New topic
Author

JAX-RS resource lifecycle

Souvik Dasgupta
Ranch Hand

Joined: Sep 24, 2009
Posts: 80

Consider the below code:




web.xml


According to JAX-RS spec: "By default a new resource class instance is created for each request to that resource" and also "Root resource classes are instantiated by the JAX-RS runtime and MUST have a public constructor for which the JAX-RS runtime can provide all parameter values.".

I found is that constructor fired before I actually hit the JAX-RS resource.Message inside constructor got printed when I hit index.jsp. My question is - Is this the way it works? I thought It will get fired when JAX-RS resource is actually hit.


Thanks and Regards, Souvik
SCJP, SCWCD, OCEJWSD
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1158
    
    1

I will try to answer your query
JAX-RS resource classes are simple POJOs. Resource has been defined with Servlet settings in web.xml with <load-on-startup> parameter as 1. This load-on-startup element is causing Jersey Servlet to load JAX-RS resource before first request.
If you do not specify a <load-on-startup> element, the servlet container will typically load your servlet when the first request arrives for it.
By setting a <load-on-startup> element, you can tell the servlet container to load the servlet as soon as the servlet container starts.
So try removing this load-on-startup element and then try to run your example.
Souvik Dasgupta
Ranch Hand

Joined: Sep 24, 2009
Posts: 80

Ok.Understood.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAX-RS resource lifecycle