English 中文(简体)
JavaEEE6 启用/禁用网络过滤器, 无需重新编码
原标题:JavaEE6 enable / disable webfilter without recompile

我将应用程序迁移到新的 JavaEE6 标准。 在创建新过滤器时, 批注非常容易使用 。 我只需要在我的 POJO 课程中添加一个 @ WebFilter 批注, 效果很好 。

令我困惑的是: 所有带有注释的过滤器都会自动由容器装入。 这有时并不可取。 我可能会创建一套过滤器, 不同的网络应用程序会选择只使用这些过滤器的子集。 因此, 我有一个问题: 是否有一个简单的方法可以启用/ 禁用基于不同部署的过滤器, 同时仍然允许我使用简单的 WebFilter 注释, 用于每个过滤器分类?

I found this article when searching on this top: Dynamically registering WebFilter with Java EE 6

但这一篇文章似乎建议不在每个过滤器类上使用注释,而是通过直接引用每个过滤器类的ServerletContextListener来装载这些注释。 这似乎不是一个最佳解决方案。

谢谢

最佳回答

这是不可能的。

您的最佳赌注是扩展过滤器,检查某些 web.xml 上下文参数,或 VM 参数,或显示不应使用过滤器的环境变量。

例如:

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if ("true".equals(System.getProperty("com.example.DISABLE_FILTER"))) {
        chain.doFilter(request, response);
        return;
    }

    // Original filter code here.
}

可以通过提供 VM 参数 - Dcom. example. disable_FILTER= true 来禁用。

问题回答

暂无回答




相关问题
Recommended way to develop using Jetty and Eclipse

I am currently developing a J2EE application and I would like to use Jetty. I would like to have iot integrated with Eclipse, so I could debug the appliaction. I ve tried out couple of plugins (...

Call function periodically in Java

we need run one function periodically in Java web application . How to call function of some class periodically ? Is there any way that call function when some event occured like high load in server ...

Why make an EJB rather than a Web Service?

I would have thought that there is a lot of information out there on this, but I haven t found anything that really answers my question. What are the advantages of making an EJB rather than a web ...

Where should I put this configuration setting?

I m designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There s ...

JNDI Names -- Is Prefix "jdbc/" needed?

What s up with JNDI names? I m trying to get a javax.sql.DataSource using the new annotations feature of Java 5. It s not working for me, so I want to ask... I have a in my web.xml, inside of it is ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

热门标签