users@glassfish.java.net

Re: InitialContext.lookup works but _at_Resource does not

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Thu, 11 Feb 2010 20:40:37 +0100

2010/2/11 Nigel Deakin <Nigel.Deakin_at_sun.com>:
> 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
>

Yes, I forgot about that - I have tried mappedName as well, didn't
work as well :/