【发布时间】:2015-11-12 13:06:44
【问题描述】:
我正在尝试将本地 @Stateless EJB 注入 Rest 异常处理程序,但出现以下错误。
javax.naming.NameNotFoundException: Name [Test] is not bound in this Context. Unable to find [Test].
maven Web 项目在 Apache-tomee-1.7.1-jaxrs 上运行。
EJB:
@Stateless(name = "Test")
public class Test {
public void sayHello() {
System.out.println("Hello");
}
}
根据我的理解,我必须将其视为 EJB 的客户端的异常处理程序。
@Provider
public class TestExceptionHandler implements ExceptionMapper<Throwable> {
@Context
HttpServletRequest request;
@Override
public Response toResponse(Throwable throwable) {
InitialContext context;
try {
context = new InitialContext();
Test test = (Test) context.lookup("Test");
test.sayHello();
} catch (NamingException ex) {
ex.printStackTrace();
}
return Response.ok().build();
}
}
我还尝试执行以下查找:context.lookup("java:comp/env/Test");
http://openejb.apache.org/jndi-names.html 文档很难理解。 还尝试了以下这是我的第一次尝试。 http://blog.iadvise.eu/2015/06/01/jee-using-ejb-and-context-annotations-in-a-jax-rs-provider-class/
我是否遗漏了 tomee 服务器或我的代码中的任何配置?
【问题讨论】:
标签: rest ejb apache-tomee