简体   繁体   English

以编程方式在web.xml中禁用过滤器

[英]Disable filter programmatically in web.xml

Is there any way we can disable filter and filter mapping declared in web.xmxl programmatically in spring mvc? 有什么办法可以在Spring MVC中以编程方式禁用在web.xmxl中声明的过滤器和过滤器映射?

I have seen that StandardContext class from tomcat api exposes methods to add filter and filter mapping and remove them too. 我已经看到了tomcat api的StandardContext类公开了添加过滤器和过滤器映射并删除它们的方法。

The requirement is that we need to disable filter without restarting the server. 要求是我们需要禁用筛选器而不重新启动服务器。 If there is any way that can be done in spring mvc, I can expose a rest api for the same using which we can enable and disable filters as and when we want. 如果在Spring MVC中可以做任何事情,我可以公开一个rest api,使用它我们可以根据需要启用和禁用过滤器。

Any pointers in this direction are highly appreciated. 高度赞赏该方向的任何指针。 Thanks!! 谢谢!!

I see as only way to achieve this to have some kind of "disable flag" into the filter code that avoid it to work, even it's not possible to unchain it from the filter's chain. 我认为,实现此目标的唯一方法是在过滤器代码中添加某种“禁用标志”,以使其无法工作,即使无法将其从过滤器链中解脱出来也是如此。 You can create a controller that share this flag via a context attribute, reading it in each filter call and decide to work or simply "pass the hand". 您可以创建一个控制器,该控制器通过上下文属性共享此标志,在每个过滤器调用中读取它,然后决定工作还是简单地“过手”。 Of course if your filter is already a blackbox in which you cannot change code this becomes impossible. 当然,如果您的过滤器已经是一个黑匣子,您无法在其中更改代码,那么这将变得不可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM