dev@glassfish.java.net

Re: glassfish v3.1 _at_Resource is not working

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Wed, 06 Apr 2011 17:41:24 -0700

Annotations are processed only on Java EE components - check the Java EE
spec for the details.

-marina

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