You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2012/03/22 21:43:20 UTC

DO NOT REPLY [Bug 52974] New: NameNotFoundException is thrown when field/method is annotated with @Resource annotation

https://issues.apache.org/bugzilla/show_bug.cgi?id=52974

             Bug #: 52974
           Summary: NameNotFoundException is thrown when field/method is
                    annotated with @Resource annotation
           Product: Tomcat 7
           Version: 7.0.26
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: violetagg@apache.org
    Classification: Unclassified


Created attachment 28500
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28500
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"

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 52974] NameNotFoundException is thrown when field/method is annotated with @Resource annotation

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52974

violetagg@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28500|0                           |1
           is patch|                            |
  Attachment #28500|application/octet-stream    |text/plain
          mime type|                            |

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 52974] NameNotFoundException is thrown when field/method is annotated with @Resource annotation

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52974

--- Comment #1 from violetagg@apache.org 2012-03-22 20:45:03 UTC ---
Created attachment 28501
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28501
Sample application

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 52974] NameNotFoundException is thrown when field/method is annotated with @Resource annotation

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52974

--- Comment #3 from Violeta Georgieva <vi...@apache.org> 2012-03-28 20:50:47 UTC ---
Thanks and Regards
Violeta

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 52974] NameNotFoundException is thrown when field/method is annotated with @Resource annotation

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52974

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #2 from Mark Thomas <ma...@apache.org> 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.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org