如何对多个项目使用相同的ContainerRequestFilter? [英] How to use the same ContainerRequestFilter for multiple projects?

查看:413
本文介绍了如何对多个项目使用相同的ContainerRequestFilter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目A和B,其中B依赖于A.因此A的所有类都可供B使用.

I have two projects A and B in which B has dependency on A. So all the classes of A are available to B.

现在,我已经定义了ContainerRequestFilter来拦截请求中的某些信息.如果我调用项目A的端点,就会被调用.但是,如果我调用项目B的端点,就不会被调用.

Now, I've defined a ContainerRequestFilter for intercepting some information from request. This is getting invoked if I call the end points of project A. But it's not getting invoked if I call end points of project B.

显然,项目A和项目B的上下文根不同.

Obviously, the context roots of project A and project B are different.

示例: http://localhost:8080/projecta/ .. http://localhost:8080/projectb/ .....

Example: http://localhost:8080/projecta/..... http://localhost:8080/projectb/.....

两个项目都放在一个耳朵中,然后部署在同一耳朵中.

Both the projects are archived in an ear and deployed in same ear.

我实际上希望它能像@AroundInvoke拦截器一样工作.

I actually expected it to work like in the case of @AroundInvoke interceptor.

如何实现?

Wildfly 8.0 高枕无忧 Java EE 7

Wildfly 8.0 Resteasy Java EE 7

推荐答案

我已经在第二个项目的web.xml中添加了提供程序,并且它完成了工作.

I've added the providers in the web.xml of the second project and it did the work.

    <context-param>
        <param-name>resteasy.providers</param-name>
        <param-value>com.example.SampleRequestFilter,com.example.SampleResponseFilter</param-value>
    </context-param>

对于第一个项目,它不是必需的. jax-rs如何加载提供程序.对于第二个项目,我添加了上面的参数,并且可以正常工作.

For the first project, it's not required. Some how jax-rs is loading the provider. For the second project, I added the above param and it worked.

这篇关于如何对多个项目使用相同的ContainerRequestFilter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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