This content has been marked as final.
Show 4 replies
-
1. Re: EJB3: @Resource name only EJBContext, not in InitialCont
jaikiran Feb 14, 2008 8:37 AM (in response to wingtung.leung)new InitialContext().lookup("java:comp/env/jms/vpoToEmotiveQueue");
It depends on where you are doing the lookup using the InitialContext. Is this being done in the same bean where the @Resource is defined? In which case, this should work. However, if you are doing the lookup in some other component of your application, then this wont work. -
2. Re: EJB3: @Resource name only EJBContext, not in InitialCont
wingtung.leung Feb 14, 2008 11:06 AM (in response to wingtung.leung)"jaikiran" wrote:
It depends on where you are doing the lookup using the InitialContext. Is this being done in the same bean where the @Resource is defined? In which case, this should work. However, if you are doing the lookup in some other component of your application, then this wont work.
The lookup using InitialContext is located inside the bean with the @Resource annotation. Exactly the same location as the lookup with SessionContext.
I also expect it to work, but it does not. :-( -
3. Re: EJB3: @Resource name only EJBContext, not in InitialCont
jaikiran Feb 14, 2008 11:17 AM (in response to wingtung.leung)Which version of JBoss do you use? I tested this on my local JBoss-4.2.2 setup with an sample application:
@Stateless @Remote ({UserManager.class}) @RemoteBinding (jndiBinding = "RemoteUserManagerBean") @Resources( { @Resource(type = Queue.class, name = "jms/A", mappedName = "queue/A") }) public class UserManagerBean implements UserManager { /** * Instance of logger */ private static Logger logger = Logger.getLogger(UserManagerBean.class); @PersistenceContext private EntityManager entityManager; @Resource private SessionContext sessionContext; /** * @see org.myapp.ejb.UserManager#getUser(long) */ public User getUser(long id) { System.out.println("Entity manager is " + entityManager); return null; } /** * @see org.myapp.ejb.UserManager#getUsers(java.lang.String) */ public List<User> getUsers(String name) { Object obj = sessionContext.lookup("jms/A"); System.out.println("Looked up through session context = " + obj); try { Context ctx = new InitialContext(); Object obj1 = ctx.lookup("java:comp/env/jms/A"); System.out.println("Looked up java:comp/env/jms/A = " + obj1); } catch (Exception e) { e.printStackTrace(); } //blah blah blah }
Both the lookups (through sessionContext and InitialContext) return me the queue object.
Can you post your code and also the entire exception stacktrace that you are seeing? -
4. Re: EJB3: @Resource name only EJBContext, not in InitialCont
wingtung.leung Feb 15, 2008 7:44 AM (in response to wingtung.leung)"jaikiran" wrote:
Which version of JBoss do you use? I tested this on my local JBoss-4.2.2 setup with an sample application:
JBoss-4.0.5 with extra EJB3 support.
I have tested it on JBoss-4.2.2, and it works fine there. So we will need to update our EJB3 component, or upgrade JBoss completely.
The original exception:Exception in thread "Main Thread" javax.naming.NameNotFoundException: env not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:267) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:351)
Thanks for the solution!