|
Referring another bean from within the same container |
|
|
An EJB client is any object that contacts an EJB. For this contact to work, EJBs need to know how to find each other. In most EJB applications, completing business logic in one EJB involves invoking another EJB. In this case invoking bean is a client.
To invoke a method from another EJB in the same container, from the client EJB, add a method for looking up the
home object of the needed EJB like in the example below.
With a reference to the home object, you can invoke any methods declared by the interface.
...
private SomeBeanHome getSomeBean() {
try {
// creates a default InitialContext instance:
Context ic = new InitialContext();
// performs JNDI lookup of the EJB home-object:
SomeBean passwordHome = (SomeBean) ic.lookup("test.someHome");
return passwordHome;
} catch (NamingException error) {
error.printStackTrace();
return null;
}
}
...
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.