According to the section EE.5.2.3 of the Java EE specification: ------------------------ Resource annotations may appear on any of the classes listed above, or on any superclass of any class listed above. A resource annotation on any class in the inheritance hierarchy defines a resource needed by the application component. ------------------------ I use JSF managed beans with @EJB annotated members. If a resource is annotated in a super class of a class it's not injected. Example: public class Base{ @EJB private SomeService service; .... } public class Child implements Base{ .... } Base class used as managed bean has 'service' injected. Child class used as managed bean does NOT have 'service' injected. If I dare suggest the problem source ... As I can see org.apache.catalina.util.DefaultAnnotationProcessor is used. It has the following lines in its 'public void processAnnotations(Object instance)' method: .... Field[] fields = instance.getClass().getDeclaredFields(); .... Method[] methods = instance.getClass().getDeclaredMethods(); .... Class.getDeclaredFields method returns 'public, protected, default (package) access, and private fields, but excludes inherited fields'. The same thing is with Class.getDeclaredMethods.
A fix has been committed to trunk and proposed for 6.0.x
This has been fixed in 6.0.x and will be included in 6.0.18 onwards.
*** Bug 45869 has been marked as a duplicate of this bug. ***
I downloaded Tomcat 6.0.18 yesterday and tried again. With the workaround mentioned in the JSF bug, which is to add the context-param for injectionProvider, the problem is still there <context-param> <param-name>com.sun.faces.injectionProvider</param-name> <param-value>com.sun.faces.vendor.WebContainerInjectionProvider</param-value> </context-param> Your comments indicated that this bug is fixed in 6.0.18.
Sorry - my bad. The fixed missed the preDestroy and postContruct methods. I'll get that fixed.
Created attachment 22728 [details] postConstruct/preDestroy in super classes Here is a patch that is fixing this issue for postConstruct/preDestroy methods in super classes (private)
Thanks for the patch. I don't have the compile environment, so will just close verify the bug in the next build.
Created attachment 22738 [details] Updated patch for fields/methods I notice that the fix that was done by Mark wasn't right also for attributes/methods. Because even if we go in the upper classes with a loop, when checking the field/methods we were using instance.getClass() and not the clazz object so fields/methods of superclasses were never obtained. Also the default name for ENC field/methods should contain the super class name and not the instance name, so I added the clazz parameter to the lookup methods.
Created attachment 22739 [details] binary of the patch For people without compiling env, here is the class
Thanks for the review and the new patch. I didn't apply the new patch directly as there were a number of white space changes that made it harder to read. The proposed patch is http://people.apache.org/~markt/patches/2008-10-20-bug45285-v2.patch
This has been applied to 6.0.x and will be in 6.0.19 onwards.