[jboss-user] [JNDI/Naming/Network] - EJB3: @Resource name only EJBContext, not in InitialContext

wingtung.leung do-not-reply at jboss.com
Thu Feb 14 08:04:11 EST 2008


I have a simple EJB3 session bean with EJB3 annotations to define external resources in the JNDI tree. Problem is that the lookup only works if I use the SessionContext, without the "java:comp/env" prefix, but NOT with InitialContext(), including the prefix. The latter version throws a NamingException.

Am I wrong if I assume that using InitialContext and EJBContext for lookup are equivalent, as long I add the prefix in the first case, and leave it out in the second one?

I used class level annotations to define the mapping:

  | @Resources( {
  |         @Resource(type = Queue.class, name = "jms/vpoToEmotiveQueue", mappedName = "jms/queue/vpoToEmotiveQueue"),
  |         @Resource(type = Queue.class, name = "jms/varQueue", mappedName = "jms/queue/lemansVarToEmotiveQueue") })
  | 

This works fine:

  | @Resource private SessionContext sessionContext;
  | ...
  | sessionContext.lookup("jms/vpoToEmotiveQueue");
  | 

But following code raises a NamingException:

  | new InitialContext().lookup("java:comp/env/jms/vpoToEmotiveQueue");
  | 




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4129384#4129384

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4129384



More information about the jboss-user mailing list