Skip to main content

@Resource does not work if stated in the parent class

5 replies [Last post]
armanis
Offline
Joined: 2007-09-25
Points: 0

I have created a base class to handle my REST web services:

public abstract class RestHandler implements Provider
{
@Resource protected WebServiceContext wsContext;

/** Creates a new instance of RestHandler */
public RestHandler()
{
}

public Source invoke(Source source)
{
// implementation goes here
}
}

and subclasses of it

@WebServiceProvider
@BindingType(HTTPBinding.HTTP_BINDING)
public class RepositoryRest extends RestHandler
{
@Resource protected WebServiceContext wsContext2;

/** Creates a new instance of Repository */
public RepositoryRest()
{
System.out.println(wsContext);
System.out.println(wsContext2);
}
}

The problem is that @Resource in RestHandler is not been triggered when JAX-WS instantiates subclasses of RestHandler. I am getting a null value in the wsContext object.

As per @Resource documentation ( http://72.5.124.55/javaee/5/docs/api/javax/annotation/Resource.html ), "Even though this annotation is not marked Inherited, deployment tools are required to examine all superclasses of any component class to discover all uses of this annotation in all superclasses. All such annotation instances specify resources that are needed by the application component. Note that this annotation may appear on private fields and methods of superclasses; the container is required to perform injection in these cases as well."

Apparently this problem has been fixed for EJB injection:
http://fisheye5.cenqua.com/search/glassfish/?comment=6392618
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6392618
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6365616
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6391353

Has anyone found a solution for this problem? Is it really a bug?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jitu
Offline
Joined: 2003-06-14
Points: 0

May be you can file a bug. I will find out from the spec guys why they made a conscious decision not to put @Inherited on @Resource.

jitu
Offline
Joined: 2003-06-14
Points: 0

Just file a bug. We need to fix it.

jitu
Offline
Joined: 2003-06-14
Points: 0
armanis
Offline
Joined: 2007-09-25
Points: 0

Sorry, I reported the bug in the Sun Developer Network (SDN) because I spent nearly 1 hours looking for "a link" saying "report a bug" on the java.net but I could not find one. Neither it can be found by Google.

Thanks for confirming the problem and creating the bug ticket for me ;)

jitu
Offline
Joined: 2003-06-14
Points: 0

Fixed. 2.1.3 nightly should have the fix.