Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does @EJB Annotation work for remote call?

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 above line of code work when I have EJB and Servlet deployed on different servers? or I need to call it through traditional way????

like image 906
B. S. Rawat Avatar asked Oct 20 '11 16:10

B. S. Rawat


People also ask

How does EJB annotation work?

In EJB 3.0, annotations are used to describe configuration meta-data in EJB classes. By this way, EJB 3.0 eliminates the need to describe configuration data in configuration XML files. EJB container uses compiler tool to generate required artifacts like interfaces, deployment descriptors by reading those annotations.

Where is it possible to use dependency injection annotations in EJB 3. 0 such as@ Resource and EJB?

EJB 3.0 specification provides annotations, which can be applied on fields or setter methods to inject dependencies. EJB Container uses the global JNDI registry to locate the dependency. Following annotations are used in EJB 3.0 for dependency injection. @EJB − used to inject other EJB reference.


1 Answers

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

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

like image 97
Piotr Nowicki Avatar answered Oct 15 '22 03:10

Piotr Nowicki