EJB lookup example
This examples describes you the lookup method used in EJB.
Bean30Remote.java:-This is the Remote interface which extends javax.ejb.EJBObject package. These are similar to RMI Remote interface. The use of remote interface is particularly helpful in providing business-specific functionality of an EJB. Here @Remote is the annotation used to declare the interface as Remote.
Bean30Remote.java
|
Bean30Bean.java:-This
is the bean of type session in which we have defined the body of the
method which were declared in the
interface named SessionBeanRemote.java.@Stateless is the annotation used
to declare the bean as a session type.
@Stateless(mappedName="Bean30"):-It is used to change the mapped name from Bean30Bean to Bean30.After
this we will use Bean30 to look up the bean in our application client.
Bean30Bean.java
|
Main.java:-This is the client application from which we can access the methods which are defined in the bean.
InitialContext ctx = new InitialContext():-InitialContext is the class which is used to find out the starting context for performing naming operations. Initial Context is used to lookup home interfaces with inside an EJB. Here all the naming convention are relative to context.
Bean30Remote br = (Bean30Remote) ctx.lookup("Bean30"):-This is the method that is used to retrieve the named object i.e. ("Bean30").
Main.java
package ejbmodule30;
|
Output of the program
================================= EJB message is:Roseindia.net Company name is:Roseindia.net Pvt.Ltd. Address is:Sec-3,D-16/116,Rohini ================================= |