禁用@WebFilter(嵌入在依赖jar中) [英] Disable @WebFilter (embedded in dependency jar)

查看:926
本文介绍了禁用@WebFilter(嵌入在依赖jar中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法禁用嵌入式Servlet过滤器?

Is there a way to disable a embedded Servlet Filter?

我的项目有一个依赖jar,它包含(在jar里面)一个 @ WebFilter 映射到/ *

我需要jar(它有很多公共类我的公司),但这个新项目不需要这个WebFilter,实际上这个新项目将无法工作,因为这个过滤器检查用户身份验证,而新项目没有loggedUser。它就像一个网站

My project has a dependency jar that contains (inside the jar) a @WebFilter mapped to "/*".
I need the jar (it has a lot of commons class of my company), but this new project does not need this WebFilter, actually this new project will not work because this Filter checks user authentication and the new project has no "loggedUser". It's like a website

谢谢

推荐答案

web.xml 优先于注释。只需在 web.xml 中声明有问题的过滤器,并将其< filter-mapping> 设置为某种东西虚假,例如:

web.xml takes precedence over annotations for precisely this reason. Simply declare the offending filter in web.xml the good old way and set its <filter-mapping> to something bogus, eg:

<filter>
    <filter-name>BadBadFilter</filter-name>
    <filter-class>com.example.BadBadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>BadBadFilter</filter-name>
    <url-pattern>/this-path-does-not-exist/*</url-pattern>
</filter-mapping>

这将有效地禁用它。

这篇关于禁用@WebFilter(嵌入在依赖jar中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆