Reputation:
Spent half a day solving the problem of ejb client lookup in glassfish 4.
The bean:
@Stateless
@LocalBean
public class TestBean implements TestRemote{
@PersistenceContext(unitName = "testunit")
private EntityManager em;
public String sayHello() {return "hello";}
}
The remote business interface:
@javax.ejb.Remote
public interface TestRemote {
public String sayHello();
}
Client lookup code, tried the following variants (the client can be in another machine, but in this test they are running on the same machine):
new InitialContext().lookup("java:global/myproject/TestBean");
new InitialContext().lookup("java:global/myproject/TestRemote");
new InitialContext().lookup("TestRemote");
new InitialContext().lookup("TestBean");
new InitialContext().lookup(TestBean.class.getName());
The project is deployed as a war (myproject.war).
Upvotes: 1
Views: 239
Reputation: 3191
If you're using glassFish, it normally says what the portable JNDI name is in the logs e.g:
INFO: EJB5181:Portable JNDI names for EJB ProductsBean: [java:global/products-ejb/ProductsBean, java:global/products-ejb/ProductsBean!com.sample.product.ejb.ProductsRemote]
so yours will be along the lines of:
java:global/<ejb-module-name>/TestBean
This looks similar to your question but I could not tell whether "myproject" was the Enterprise Application Name or the EJB Module name...
or
java:global/<enterpriseApplicationName>/<ejb-module-name>/TestBean!<package_of_remote>.TestRemote
Upvotes: 0
Reputation:
This works:
new InitialContext().lookup("com.example.TestRemote");
Upvotes: 1