[EJB 3.0] - Re: Lookup EJB via JNDI
by 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);
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172952#4172952
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172952
17 years, 7 months
[EJB 3.0] - Re: Lookup EJB via JNDI
by jaikiran
Post the code of your bean.
anonymous wrote : 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.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172946#4172946
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172946
17 years, 7 months
[EJB 3.0] - Lookup EJB via JNDI
by hipa
How can I lookup EJB via JNDI like @EJB annotation do it? I don't know neither application name nor bean name at compile time.
| ...
| @EJB
| private BeanLocal bean;
| ...
|
I tried using InitialContext:
| new InitialContext().lookup("BeanLocal/local");
|
It doesn't work because of I need to specifiy application name here:
| new InitialContext().lookup("MyApp/BeanLocal/local");
|
Then I tried using java:comp/env:
| ...
| @Resource
| private EJBContext ctx;
| ...
| ctx.lookup("BeanLocal");
| ...
|
But it always returns null. It's because of my java:comp/env includes only the current bean.
I know there must be a method to lookup EJB. If not how does @EJB annotation work (I couldn't find implementation of @EJB annotation in JBoss 5.0.0 sources)?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172937#4172937
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172937
17 years, 7 months