users@glassfish.java.net

Re: InitialContext.lookup works but _at_Resource does not

From: Nigel Deakin <Nigel.Deakin_at_Sun.COM>
Date: Thu, 11 Feb 2010 16:00:17 +0000

Witold,

Witold Szczerba wrote, on 11/02/2010 15:41:
> Hi there,
> I have problem in one of my session bean deployed on Glassfish v2.1.1.
> The bean is supposed to send messages to WebSphere MQ using WebSphere
> MQ JCA Adapter. So, in order to send a message it needs two objects:
> ConnectionFactory and Queue.
> When I look for those objects using InitialContext, everything works
> and messages are sent.
>
> The code below works:
> ----------------------------------------
> ConnectionFactory ivtcf = null;
> Queue ivtQueue = null;
> try {
> InitialContext ctx = new InitialContext();
> ivtcf = (ConnectionFactory) ctx.lookup("jms/IVTCF");
> ivtQueue = (Queue) ctx.lookup("jms/IVTQueue");
> } catch (NamingException ex) {
> throw new RuntimeException(ex);
> }
>
> logger.info("ivctf="+ivtcf);
> logger.info("ivtQueue="+ivtQueue);
> ----------------------------------------
>
>
> The problem is I cannot use @Resource injection to get rod of those
> InitialContext lookups and NamingExceptions:
> ----------------------------------------
> @Resource(mappedName = "jms/IVTCF")
> private ConnectionFactory ivtcf;
> @Resource(mappedName = "jms/IVTQueue")
> private Queue ivtQueue;
> ----------------------------------------

Does it work if you try name instead of mappedName?

@Resource(name = "jms/IVTCF")
private ConnectionFactory ivtcf;
@Resource(name = "jms/IVTQueue")
private Queue ivtQueue;

Nigel