JAX – RS Sub Packages Scan configuration Example

In this example we will see how Jersey will automatically discover the resources and providers in the selected packages and sub packages. This can be achieved by configuring properties in web.xml by using <init-param>  like as below.

 

 

 

1. Create Dynamic web project in Eclipse.

RestfulSubPackagesScanExample_proj

 

 

2. Write Java Resource classes.

 
 

3. Configure the Jersey Servlet and  <init-param> in web.xml

4. Run the Example

Deploy the application and try to see below scenarios.

NOTE : I have not included all the required jersey jars in the source code please download it from here and copy to lib folder.

OUT PUT:

scenario1

If we  setting the  jersey.config.server.provider.scanning.recursive property as “true” in web.xml , Jersey servlet will recursively scan all sub-packages.

In the above scenario we can able access all the resources.

 

RestfulSubPackagesScanExample2

 

scenario2

If we  setting the jersey.config.server.provider.scanning.recursive  property as “false” or empty in web.xml , Jersey servlet will not recursively scan all sub-packages it will scan only com.connect2java.department

In the above scenario we can able to access only one  resource i.e Department resource.

 

RestfulSubPackagesScanExample1

 

Download  Source Code

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted in webservices.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">