Wednesday, January 4, 2017

How to avoid Jersey Servlet to scan Default location?


Jersey container scans by default in the below location with respect to our application(s):

INFO: Scanning for root resource and provider classes in the Web app resource paths:
/WEB-INF/lib
/WEB-INF/classes

Solution 1: Limit the jersey servlet container to specific to your folders (pack,pack2). Rest of the folder it ignores

       <servlet>
<servlet-name>Jersey Restful Services</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.test.pack,com.test.pack2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

Solution 2: Disable auto scan the rest services
        <!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
        <context-param>
                   <param-name>resteasy.scan.resources</param-name>
                    <param-value>false</param-value>
       </context-param>
       <context-param>
                    <param-name>resteasy.scan.providers</param-name>
                      <param-value>false</param-value>

        </context-param>

blow are the other option we can choose based on need.

Option NameDefault ValueDescription
resteasy.servlet.mapping.prefixno defaultIf the url-pattern for the Resteasy servlet-mapping is not /*
resteasy.scanfalseAutomatically scan WEB-INF/lib jars and WEB-INF/classes directory for both @Provider and JAX-RS resource classes (@Path, @GET, @POST etc..) and register them
resteasy.scan.providersfalseScan for @Provider classes and register them
resteasy.scan.resourcesfalseScan for JAX-RS resource classes
resteasy.providersno defaultA comma delimited list of fully qualified @Provider class names you want to register
resteasy.use.builtin.providerstrueWhether or not to register default, built-in @Provider classes. (Only available in 1.0-beta-5 and later)
resteasy.resourcesno defaultA comma delimited list of fully qualified JAX-RS resource class names you want to register
resteasy.jndi.resourcesno defaultA comma delimited list of JNDI names which reference objects you want to register as JAX-RS resources
javax.ws.rs.Applicationno defaultFully qualified name of Application class to bootstrap in a spec portable way
resteasy.media.type.mappingsno defaultReplaces the need for an Accept header by mapping file name extensions (like .xml or .txt) to a media type. Used when the client is unable to use a Accept header to choose a representation (i.e. a browser). See JAX-RS Content Negotiation chapter for more details.
resteasy.language.mappingsno defaultReplaces the need for an Accept-Language header by mapping file name extensions (like .en or .fr) to a language. Used when the client is unable to use a Accept-Language header to choose a language (i.e. a browser). See JAX-RS Content Negotiation chapter for more details