dev@glassfish.java.net

Re: glassfish v3.1 _at_Resource is not working

From: Ancoron Luciferis <ancoron.luciferis_at_googlemail.com>
Date: Thu, 07 Apr 2011 00:12:45 +0200

On 04/06/2011 11:37 AM, java4dev wrote:
> Hello,
> I am using glassfish v3.1.
> I have created a custom Resource of type Properties and try to load it
>
> public class DBUtilities {
> @Resource(name="custom/application")
> static private Properties properties;
>
> This will never load the resource into the variable properties.
> static has no effect. It doesn't matter if properties is a class member
> or an instance member variable.
>
> but if I do
>
> Context context = null;
> try {
> context = new InitialContext();
> properties = (Properties)
> context.lookup("java:comp/env/custom/application");
> } catch (NamingException ex) {
>
> Logger.getLogger(DBUtilities.class.getName()).log(Level.SEVERE, null, ex);
> }
>
> then it loads the resource.
> Why is it so that the @Resource annotation is not working?
> I have even tryed with other resources with the same problem e.g.
> javax.mail.Session
>
> thank you
> Nikolas

Hi Nikolas,

I think the ResourceHandler of GF 3.1 is at fault here, as it is not
that generic (yet).

The "only" things that the @Resource annotation handler implementation
handles are these, as it seems:

javax.jms.Queue
javax.jms.Topic
javax.sql.DataSource
javax.jms.ConnectionFactory
javax.jms.QueueConnectionFactory
javax.jms.TopicConnectionFactory
javax.mail.Session
java.net.URL
javax.resource.cci.ConnectionFactory
org.omg.CORBA_2_3.ORB
org.omg.CORBA.ORB
javax.jms.XAConnectionFactory
javax.jms.XAQueueConnectionFactory
javax.jms.XATopicConnectionFactory

+ JMS destinations
+ Web Service stuff

...so, this would explain what you are experiencing currently. It would
be nice if we would have a fallback here to JNDI internally, or the
internal resource reference stuff, but there might be problems (as I'm
not that much involved into this topic).

However, if you want to have a look by yourself grab the code and have a
look inside this class:

com.sun.enterprise.deployment.annotation.handlers.ResourceHandler

inside project v3/deployment/dol.


Cheers,

        Ancoron