Bug 52974 - NameNotFoundException is thrown when field/method is annotated with @Resource annotation
Summary: NameNotFoundException is thrown when field/method is annotated with @Resource...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.26
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-22 20:43 UTC by Violeta Georgieva
Modified: 2012-03-28 20:50 UTC (History)
0 users



Attachments
Patch proposal (15.75 KB, patch)
2012-03-22 20:43 UTC, Violeta Georgieva
Details | Diff
Sample application (2.31 KB, application/x-zip-compressed)
2012-03-22 20:45 UTC, Violeta Georgieva
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Violeta Georgieva 2012-03-22 20:43:20 UTC
Created attachment 28500 [details]
Patch proposal

Hi,

I have a web application (attached) that has a Servlet with an annotated (@Resource) field and an annotated (@Resource) method.

When I request the Servlet I'm receiving:

javax.naming.NameNotFoundException: Name test.TestServlet is not bound in this Context
  org.apache.naming.NamingContext.lookup(NamingContext.java:820)
  org.apache.naming.NamingContext.lookup(NamingContext.java:168)
  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)


I searched the sources and found that org.apache.catalina.startup.WebAnnotationSet processes and prepares for binding only @Resource annotation on a class level. However org.apache.catalina.core.DefaultInstanceManager tries to process @Resource annotation on field/method level and to inject the necessary Object. Unfortunately as the information is not processed and bound in the naming previously, NameNotFoundException is thrown.

I would like to propose a patch (attached).

I'm looking forward to your comments.

Thanks in advance.

Regards
Violeta Georgieva


Steps to reproduce the issue:

1. Deploy the attached web application
2. Request http://localhost:8080/test/TestServlet
3. NameNotFoundException is thrown
4. Apply the patch and restart Tomcat
5. Request http://localhost:8080/test/TestServlet
6. You should see in the browser "Annotated field: test Annotated method: test1"
Comment 1 Violeta Georgieva 2012-03-22 20:45:03 UTC
Created attachment 28501 [details]
Sample application
Comment 2 Mark Thomas 2012-03-27 19:28:05 UTC
Many thanks for the patch.

It has been applied to trunk and 7.0.x and will be included in 7.0.27 onwards.
Comment 3 Violeta Georgieva 2012-03-28 20:50:47 UTC
Thanks and Regards
Violeta