1

Is there something special I have to do to enable Jar scanning for @WebFilter in Tomcat7 or TomEE 1.6? I have an empty 3.0 spec web.xml, a beans.xml in web-inf, and my @WebFilter is in a CDI compliant JAR (not that the servlet spec would really care I guess).

The filter works if I enable it manually in the web.xml. If I copy/paste the class into the WAR project, Tomcat/Tomee picks up the @WebFilter annotated class.

Thanks!

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84

2 Answers2

3

I was scratching my head too over my @WebFilter class not being picked up, and ended up reading something (can't remember where) that referenced the metadata-complete attribute in the web.xml root tag needing to be false, or just not added to the tag at all (default is false).

When I removed that attribute from my web.xml root tag so that it looked like this:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">

it picked up my @WebFilter class immediately, with no references in the web.xml file. Not sure if this helps, but hopefully it will help someone.

j.snyder
  • 505
  • 1
  • 7
  • 14
  • 1
    This was very helpful. I was frustrated and even debugged the tomcat/servlet code base. So basically what happens is if the `metadata-complete` is set to true, we say the web.xml is complete and don't need to scan for annotation such as `WebFilter`. However it improves the startup time. See more at https://stackoverflow.com/questions/9820379/what-to-do-with-annotations-after-setting-metadata-complete-true-which-resolv – Bee Dec 03 '22 at 23:06
  • That's exactly it!!! Tks a lot!!! – Jose Aug 07 '23 at 22:33
1

isn't the jar filtered? Maybe an ignored prefix

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13