1

In my Servlet application, I'm using a Jar which contains an @WebFilter class in it. I should not remove the Jar dependency or the @WebFilter class inside it. I tried to set some bogus filter url pattern for the unwanted filter, but it doesn't work as that @WebFilter is mapped to /*.

 package com.somepackage;

 @WebFilter("/*")
 public class CustomFilter implements Filter {

This is how I set the bogus url in web.xml

<filter>
    <filter-name>CustomFilter</filter-name>
    <filter-class>com.somepackage.CustomFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CustomFilter</filter-name>
    <url-pattern>/thispathnotexist/*</url-pattern>
</filter-mapping>

It doesn;t have any effect as all the requests are still passed through CustomFilter. Is there any way that I can disable this particular filter in my appliction?

The Coder
  • 2,562
  • 5
  • 33
  • 62

1 Answers1

0

web.xml overrides the annotation. You can declare it in web.xml and with some dummy path

I believe you are looking for Disable @WebFilter (embedded in dependency jar)

Community
  • 1
  • 1
M Sach
  • 33,416
  • 76
  • 221
  • 314
  • @M Sach, I've already tried that as stated in my post, still the requests are passed through custom filter – The Coder Dec 22 '15 at 13:05
  • it should work. But still In that case you can try have filter with same name which will do nothing and put it in `web-inf/classes` – M Sach Dec 22 '15 at 13:15
  • It would only work if the filter name is the same. However, the @WebFilter doesn't have a filter name defined. So basically you're just adding another one. – BalusC Dec 22 '15 at 13:38
  • @BalusC in this case under web.xml filtername does not matter. what will matter is filter class name – M Sach Dec 22 '15 at 13:44