Reputation: 4630
My questions are:
Q 1. How to enable Package Scanning in JBOSS, so that it may know that where to look for implementation classes and the providers(the one annotated with @Provider) in a war file?
Q 2. Why my filter was not registered by the application class, and I had to do it in web.xml?
Scenario
I created a Jax-RS webservice using Jersey and deployed it in JBOSS-6, firstly I came across an error that depicts that JBOSS will not be able to Scan through the packages, that I have provided in the web.xml to find my Rest webservice implementations.
So the way around was to create an Application
class,(I prevented myself from using the ResourceConfig
provided by Jersey itself for no specific reason) and registered my WebService implementation in the getClasses method like the following:
public class MainApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
set.add(RESTWSImplementation.class);
set.add(SomeFilter.class);
return set;
}
}
it somewhat did the trick for me , but the filter was still not registered. i.e.
set.add(SomeFilter.class);
seems like was not working, So I mentioned that filter in my web.xml like following,
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>test.SomeFilter</param-value>
</init-param>
then everything worked perfectly. However from below text, I was expecting it to get registered straight away.
So again my questions are,
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>POCTEST</groupId>
<artifactId>POCTEST</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
</project>
Upvotes: 6
Views: 565
Reputation: 61
please show your pom.xml.
Probably your are using:
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jaksonVersion}</version>
</dependency>
Try:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${restEasyVersion}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${restEasyVersion}</version>
</dependency>
Edit:
Or you can try to add init param inside servlet tag(in web.xml):
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.your.package</param-value>
</init-param>
Upvotes: 2