Reputation: 5519
Edit: I hadn't realized that all request were first going into "Apache" and then were redirected to Tomcat. I added a new redirection in the
apache2.conf
file. See the accepted answer for details.
I am having the exact same problem as this question. Jersey REST The ResourceConfig instance does not contain any root resource classes However the user never answered the question.
I am using Tomcat, without maven. I followed this tutorial. http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/index.html
I made changes to web.xml as per the article
i.e the new servlet and servlet mapping was created with the correct package name.
<servlet>
<servlet-name>Jersey REST Service</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>sample.hello.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I have deployed the following jars to tomcat
asm.jar
jersey-server.jar
jersey-core.jar
jsr311.jar
The tomcat startup log has the following exceptions.
com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
sample.hello.resources
com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class sample.hello.resources.HelloResource
com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
When I access the URL I get a 404. http://localhost:8080/Jersey/rest/hello
The code:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class HelloResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() {
return "Hello Jersey";
}
}
I do not see any other exceptions in the logs
Upvotes: 9
Views: 30001
Reputation: 5519
This issue was resolved as follows. My localhost has been setup with "Apache" webserver which redirects all requests to Tomcat. Since "Jersey" is using a new servlet, I had to create a separate redirect for this servlet specifically.
In Linux
/etc/apache2/apache2.conf
add:
JkMount /rest/* ajp13_worker
Upvotes: 5
Reputation: 7996
By default, Tomcat uses war file name or name of the top most directory of the exploded war as root context unless defined in catalina_home/conf/server.xml, catalina_home/conf/context.xml or in application's META-INF/context.xml file.
To access http://localhost:8080/Jersey/rest/hello, the context entry should be <Context path="/Jersey" docBase="myapp"/>
and your resource should have @Path("/rest/hello")
.
Upvotes: 1
Reputation: 7661
Verify you have the right URL:
The tomcat manager application is happy to direct you to the root URL of the servlet. (you are assuming this is "Jersey" with capital J.) http://localhost:8080/manager/html/list
Then you can skip the "rest" part by setting the URL pattern in the servlet mapping of the web.xml to "/*" (yes, there was a bug in Jersey related to that once, but that's ancient history)
Then you can append "application.wadl" to get a description of available resources. Theoretically: http://localhost:8080/Jersey/application.wadl
Upvotes: 8