问题
I am not being able to get JAX-RS working with Resteasy 2.3.5 usingh simple @ApplicationPath annotation. Here is the code I am using:
@ApplicationPath("/rest")
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> s = new HashSet<Class<?>>();
s.add(ViewController.class);
return s;
}
}
@Path("/")
public class ViewController {
@GET
@Path("/test")
public String test() {
return "Yes!";
}
}
Requesting on "/uri-context/rest/test/" throws a 404. Using Jersey everything works seamlessly. Since this is a very trivial part of JAX-RS what's going on wrong?
Currently I am using only 4 libs of Resteasy that I would require:
- async-http-servlet-3.0-2.3.5.Final.jar
- jaxrs-api-2.3.5.Final.jar
- resteasy-jaxrs-2.3.5.Final.jar
- scannotation-1.0.3.jar
Nevertheless, putting all the libs (except for resteasy-cdi-2.3.5.Final.jar), also does not solve the problem.
回答1:
Beware with Jax-RS 1.0, the path and the slash
@ApplicationPath("api") //NO slash
public class MyApplication extends Application {
}
@Path("/users") // YES slash
public class ViewController {
@GET
@Path("all") //NO slash
public String all() {
return "Yes!";
}
}
Usually taking care of slashes makes it quickly better.
UPDATE for JAX-RS 2 :
In JAX-RS 2, the spec DOES says that leading and trailing slashes in @ApplicationPath
or @Path
will be ignored.
(3)If the resource class URI template does not end with a ‘/’ character
then one is added during the concatenation.
For what I have tested with Jersey 2 and Resteasy, this is now respected.
来源:https://stackoverflow.com/questions/14179868/resteasy-not-working-with-applicationpath