在 Apache CXF - JAX-RS 中使用 FIQL 查询时如何注入 @Context?

发布于 2024-12-06 04:18:18 字数 715 浏览 6 评论 0原文

我正在尝试实现 FIQL 搜索查询,并且遵循 http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-FIQLsearchqueries

问题是 SearchContext 始终为 null,并且我在运行时收到 NullPointerException。

我的示例代码是:

@Context
private SearchContext searchContext;

@GET
@Path("/actor/")
@Override
public List<Actor> getActorBy() {
    SearchCondition<District> sc =  searchContext.getCondition(Actor.class);
}

在 searchContext 上执行 getCondition 方法时,出现 NullPointerException。

其他休息电话正在工作。

有没有办法注入或配置 SearchContext 以便我能够执行 fiql 搜索查询?

I am trying to implement a FIQL search queries and I am following the guide at http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-FIQLsearchqueries.

The issue is that the SearchContext is always null and I am getting a NullPointerException at runtime.

My sample code is :

@Context
private SearchContext searchContext;

@GET
@Path("/actor/")
@Override
public List<Actor> getActorBy() {
    SearchCondition<District> sc =  searchContext.getCondition(Actor.class);
}

I am getting the NullPointerException when executing the method getCondition on searchContext.

The others rest calls are working.

Is there a way to inject or configure the SearchContext so I can be able to execute a fiql search query ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦言归人 2024-12-13 04:18:18

注入 @Context 似乎存在一些问题...我能够通过以下方式使其工作

 public List<Actor> getActorBy(@Context SearchContext searchContext) {
...

There seems to be some problem injecting @Context(s)... I was able to get this working by

 public List<Actor> getActorBy(@Context SearchContext searchContext) {
...
许一世地老天荒 2024-12-13 04:18:18

您需要将 SearchContextProvider 添加到 jaxrs:server

示例中:

<jaxrs:server id="myWebServices" address="/ws">
        [...]
        <jaxrs:providers>
            [...]
            <bean class="org.apache.cxf.jaxrs.ext.search.SearchContextProvider"/>
        </jaxrs:providers>
    </jaxrs:server>

You need to add a SearchContextProvider to your jaxrs:server

example:

<jaxrs:server id="myWebServices" address="/ws">
        [...]
        <jaxrs:providers>
            [...]
            <bean class="org.apache.cxf.jaxrs.ext.search.SearchContextProvider"/>
        </jaxrs:providers>
    </jaxrs:server>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文