@EJB Working with annotation for remote calling?

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()); } 

Will the above line of code work when I have EJB and Servlet deployed on different servers? or do I need to call it the traditional way ????

+6
source share
4 answers

If EJB is on a different server than your client (Servlet), than you cannot use dependency injection with @EJB annotation.

I guess you need to go with the old JNDI way.

+6
source

According to the EJB 3.1 specification, you can use the @EJB annotation for various clients, including servlets, which are your case.

The problem is that you are using the client and server on different hosts. Depending on the server you are using, you may use EJB annotation. This post explains how to do this in Weblogic.

Needless to say, you should define the EJB server as @Remote anyway.

+2
source

If your container also supports CDI, you can write a way to create a CDI for a bean that is looking for JNDI. Then you can at least separate the search from the injection site.

0
source

How about using dependency injection in a standalone client?

0
source

Source: https://habr.com/ru/post/899716/


All Articles