我正在尝试执行以下操作(很多细节,对不起......):
有一个 jax-rs 服务,@EJB
以避免 jndi 查找。就像是
@Path("rest/my-path)
public class Service {
@EJB
private MyEJB me;
@Path("foo")
@GET
public String foo() {
return me.foo();
}
}
使用CXFNonSpringJaxrsServlet
和限制url-pattern
. web.xml 应该是这样的:
<servlet>
<servlet-name>my-servlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>
com.example.Service
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>my-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
所以理论上http://localhost:8080/my-app/rest/my-path/foo
会调用,你猜对了,foo()
TomEE 的日志支持这一点:
设置服务器的发布地址为 /REST Application:
但实际上,servlet-mapping 和 jaxrs 解析器的组合使得
http://localhost:8080/my-app/rest/my-path/foo返回404
和(注意双/rest/rest/)
http://localhost:8080/my-app/rest/rest/my-path/foo actually invoke the method but MyEJB is null
Didn't find any combination of servlet-mapping and service path and jaxrs.address
that makes the root url return the index.html and the correct service url is calling foo and MyEJB is not null
Any ideas om how to solve this?