@EJB 注释是否适用于远程调用?
问题描述:
public class Servlet2Stateless extends HttpServlet {
@EJB private HelloUserLocal helloUser;
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println(newSess.getName());
}
当我在不同的服务器上部署 EJB 和 Servlet 时,上面的代码行会起作用吗?或者我需要通过传统方式调用它????
will above line of code work when I have EJB and Servlet deployed on different servers? or I need to call it through traditional way????
答
如果 EJB 与您的客户端 (Servlet) 驻留在不同的服务器上,则您不能使用带有 @EJB 注释的依赖注入.
If the EJB resides on the different server than your client (Servlet) than you cannot use the dependency injection with @EJB annotation.
我猜您需要采用旧的 JNDI 方式.
I guess that you'll need to go with the old JNDI way.