This content has been marked as final.
Show 2 replies
-
1. Re: Lookup EJB via JNDI
jaikiran Aug 28, 2008 1:36 AM (in response to hipa)Post the code of your bean.
It doesn't work because of I need to specifiy application name here:
new InitialContext().lookup("MyApp/BeanLocal/local");
That's the default JNDI name given to the bean. You can override it by using @RemoteBinding or @LocalBinding annotation on your bean. Here's an example:
import org.jboss.ejb3.annotation.LocalBinding;
import org.jboss.ejb3.annotation.RemoteBinding;@Stateless @LocalBinding (jndiBinding="MyUserManagerBeanLocal") @RemoteBinding (jndiBinding = "MyUserManagerBeanRemote") public class UserManagerBean implements UserManagerLocal, UserManagerRemote {
You can then use the MyUserManagerBeanLocal or MyUserManagerBeanRemote as the jndi name in the JNDI lookup. -
2. Re: Lookup EJB via JNDI
hipa Aug 28, 2008 1:55 AM (in response to hipa)I can't modify bean that I want to lookup.
@Local public interface LookupBeanLocal { public Object lookup(String name); } @Stateless public class LookupBean implements LookupBeanLocal { public Object lookup(String name) { // Here I need to get bean with name 'name' } }
Then in other bean I want to get bean by name like @EJB annotation can do:@Stateless public class MyBean implements MyBeanLocal { @EJB private LookupBeanLocal lookupBean; @EJB(name = "MyBean") private MyBeanLocal myBean; public void test() { MyBeanLocal me = (MyBeanLocal) lookupBean.lookup("MyBean"); assert myBean.equals(me); } }