问题
Environment
Windows 7(64)
jdk1.7.0_51(64)
RESTEasy3.0.7
apache-tomcat-7.0.50
Project Name: hello
RESTEasyHelloWorldService.java:
package com.javacodegeeks.enterprise.rest.resteasy;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/RESTEasyHelloWorld")
public class RESTEasyHelloWorldService {
@GET
@Path("/{param}")
@Produces(MediaType.TEXT_PLAIN)
public String getMsg(@PathParam("param") String name) {
String msg = "Rest say: good " + name;
return msg;
}
}
web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>hello</display-name>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
</web-app>
why do I get the exception when I call the http://localhost:8080/hello/rest/RESTEasyHelloWorld/a
returns:
javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/hello/rest/RESTEasyHelloWorld/a
at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
...
回答1:
You could try to use http://localhost:8080/hello/RESTEasyHelloWorld/a
. (Without the /rest
).
If you want to use /rest
, you can modify your RESTEasyHelloWorldService @Path to /rest/RESTEasyHelloWorld
.
But based on the APIs versions you are using, you can do a much simpler job to get your restful service working.
I'm assuming you have resteasy-jaxrs lib on your classpath.
Since you are not using JBOSS or EAP, you also need to get resteasy-servlet-initializer. Documentation for using Servlet 3.0 Containers like TOMCAT here.
You will need to extend Application, creating for example a RESTEasyService:
@ApplicationPath("/rest")
public class RESTEasyService extends Application {
}
You don't need to provide any implementation for that class, since RESTEasy will scan for all providers and resources. Documentation for using Application class here.
Leave your RESTEasyHelloWorldService just like you said on your question:
@Path("/RESTEasyHelloWorld")
public class RESTEasyHelloWorldService {
@GET
@Path("/{param}")
@Produces(MediaType.TEXT_PLAIN)
public String getMsg(@PathParam("param") String name) {
String msg = "Rest say: good " + name;
return msg;
}
}
Now your web.xml doesn't need anything. Java WS-RS and RESTEasy are already doing everything.
Your web.xml can be like this:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>hello</display-name>
</web-app>
RESTEasy official documentation is a little confusing at start, but once you understand that the implementation is the same for JBOSS and NON-JBOSS apps (just the use of libs that change), you get things going easier.
回答2:
I got the same issue when I tried with 3.0.11.Final
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.11.Final</version>
</dependency>
but when I tried with another version it worked.
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.4.Final</version>
</dependency>
And moreover The URL(http://localhost:8080/hello/rest/RESTEasyHelloWorld/a) which you are trying is correct since you have mentioned /rest in the web.xml .Hope this helps.
回答3:
I had the same problem when I was migrating my app from resteasy version 3.0.4 to 3.0.12
Web service was working fine with web.xml similar to one that user3926093 pasted above. What I released is that version 3.0.7 is changing point. Before that version you didn't even need resteasy-servlet-initializer as fasfsfgs stated above. But with 3.0.7 and later versions I started getting "Could not find resource for full path:" exception.
What I did in order to make it work is to change web.xml to look the same as fasfsfgs stated above (basically I removed all configuration from it) and I created subclass of javax.ws.rs.core.Application class also as fasfsfgs stated above but I don't agree that "You don't need to provide any implementation for that class". The way how you could implement this class could be found here: https://goo.gl/9TJ3Y2. Note that if you want per-request model than this implementation is not good for you. And lastly don't forget to add resteasy-servlet-initializer dependency.
来源:https://stackoverflow.com/questions/25224581/javax-ws-rs-notfoundexception-could-not-find-resource-for-full-path