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????
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With