Created attachment 26031 [details] propose fix for a couple possible async listener problems I asked about these on the dev list and am proposing some simple fixes in case there's agreement that they are bugs. 1. AsyncListeners are subject to resource injection from annotations, so they should be created using the instance manager. To get the instance manager to the AyncContextImpl I added a getInstanceManager() method to the Context interface. Maybe there's a better way, this interface is currently not very small or simple. 2. various application code can use one of the ServletContext.addListener methods to tell the container to scan for annotations. Just because tomcat doesn't yet actually scan doesn't mean it should throw an exception if you try this. cf servlet 3.0 spec section 15.5 page 179.
The second point is not correct. The Javadoc (which annoyingly is considered part of the specification even though it isn't in the specification document) lists the valid listener classes and AsyncListener is not one of them. The spec requires throwing an Exception in that case.
Fixed with an alternative patch in trunk and will be included in 7.0.4 onwards. I used the same approach as is used in ApplicationFilterConfig to access the InstanceManager.
Thanks for fixing the listener creation to use instance manager. As to whether you can call addListener with an async listener, I don't think its very clear. In Section 15.5: AsyncListener is included in the list of interfaces for which << Annotations must be supported on the following container managed classes that implement the following interfaces and are declared in the web application deployment descriptor or using the annotations defined in Section 8.1, “Annotations and pluggability” on page 8-61 or added programmatically. >> Note that this indicates that AsyncListeners can be annotated with @WebListener and that the ServletContext.addListener methods can be called for an AsyncListener. Furthermore the section makes clear that resource injection must be supported for AsyncListeners defined in web.xml, with a @WebListener annotation, or added programatically, and that AsyncListeners can be managed beans. Section 4.4.3 agrees with the javadoc you cite. I think the spec contradicts itself here. I plan to ask for clarification from the e.g. by filing a tck challenge.