问题
I have a WAR with some JAX-RS services, deployed into TomEE Plus. Given a service annotated with @Path("myservice")
, TomEE+ publishes it to localhost:8080/mywebapp/myservice
.
However, that also makes accessing a JSP at localhost:8080/mywebapp/index.jsp
impossible - JAXRSInInterceptor complains that No root resource matching request path has been found, Relative Path: /index.jsp
.
So I would like to configure a path prefix api
to all services, which changes the myservice
URL to localhost:8080/mywebapp/api/myservice
. Doing so would be trivial if I had configured CXF on my own (with or without Spring), because I could simply change the URL pattern of the CXF Servlet - but I am relying on the default settings where I don't configure anything besides the annotations. So how do I do that in this case?
Note that I don't want to alter the @Path
annotations to include the prefix, because that does not fix the issue with the JSP.
回答1:
Create an extension of javax.ws.rs.core.Application and annotate it with @ApplicationPath where value would be api
in your case:
@ApplicationPath("/api")
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register root resource
classes.add(MyServiceResource.class);
return classes;
}
}
This way a Servlet 3 container would find your application and map your resource to /mywebapp/api/myservice
while making your web resources (.jsp) available at /mywebapp
.
回答2:
TomEE trunk supports these configurations: cxf.jaxrs.staticSubresourceResolution & cxf.jaxrs.static-resources-list
but the @ApplicationPath is the more relevant solution IMO
Using -Dopenejb.webservice.old-deployment=true can help too in some cases
来源:https://stackoverflow.com/questions/17739837/how-can-i-configure-the-jax-rs-base-path-in-tomee