tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Bourque <christian.bour...@gmail.com>
Subject Re: SessionContext lookup
Date Mon, 04 May 2009 00:31:29 GMT
Hi David,

I already know this method but I need to inject (lookup) ejbs
dynamically so it is useless for me...

I guess my only choice left is to use the 'new InitialContext()' alternative?

Thanks

Christian

On Sun, May 3, 2009 at 3:42 PM, David Blevins <david.blevins@visi.com> wrote:
> Hi Christian,
>
> Try this:
>
>    @Stateless
>    public class OrangeBean implements OrangeLocal
>    {
>
>        public String echo(String s)
>        {
>            return s;
>        }
>    }
>
>    @EJB(name="orange", beanInterface = OrangeLocal.class)
>    @Stateless
>    public class TestBean implements TestLocal
>    {
>       @Resource
>       private SessionContext sessionContext;
>
>       public void test()
>       {
>           OrangeLocal orangeLocal = (OrangeLocal)
> sessionContext.lookup("orange");
>       }
>    }
>
> The @EJB annotation declares a reference to the Orange bean.  The
> sessionContext.lookup is a convenience method around 'new
> InitialContext().lookup("java:comp/env/"+name)' and by default the
> 'java:comp/env' namespace is empty unless references are declared via
> annotation or xml.
>
> -David
>
>
> On May 1, 2009, at 2:28 PM, Christian Bourque wrote:
>
>> Hi,
>>
>> What JNDI path should I use to lookup an EJB using a SessionContext
>> which has been injected:
>>
>> @Stateless
>> public class TestBean implements TestLocal
>> {
>>   @Resource
>>   private SessionContext sessionContext;
>>
>>   public void test()
>>   {
>>       sessionContext.lookup("???");
>>   }
>> }
>>
>> I've tried different combinations without any success...
>>
>> Thanks
>>
>> Christian
>>
>
>

Mime
View raw message