簡體   English   中英

使用RestEasy的UriInfo的Guice提供程序

[英]Guice provider for UriInfo using RestEasy

我有一個網絡應用程序正在從Jersey移植到RestEasy。 該應用程序將Guice用於CDI。

該應用程序使用Guice提供程序注入UriInfo。 在Jersey版本中,此代碼如下所示

public static class JerseyIntegrationModule extends AbstractModule {
    @Override protected void configure() {
        bind(WebApplication.class).to(WebApplicationImpl.class).in(Scopes.SINGLETON);
    }

    @Provides @RequestScoped
    public HttpContext getHttpContext(WebApplication webapp) {
      return webapp.getThreadLocalHttpContext();
    }

    @Provides @RequestScoped
    public UriInfo getUriInfo(HttpContext httpContext) {
      return httpContext.getUriInfo();
    }
}

所有這些類WebApplicationHttpContext等都是特定於Jersey的。 問題是如何在RestEasy下提供類似的功能。

一種嘗試是

public class MyServlet extends ServletModule {
    @Provides @RequestScoped
    public UriInfo getUriInfo(@Context UriInfo info) {
        return info;
    }
}

但這會導致Guice的注入代碼中的堆棧溢出。

我知道@Context屬性應該讓我在RestEasy下注入UriInfo,但是我不知道要在Guice提供程序中使用它。

該應用程序將部署在Wildfly 15上。

非常感謝任何幫助,因為這使我頭昏腦脹。

似乎有一種解決方案

public class MyServlets extends ServletModule {

  @Provides @RequestScoped
  public UriInfo getUriInfo() {
    return ResteasyProviderFactory.getContextData(UriInfo.class);
  }

}

Resteasy帶有提供UriInfo,HttpServletRequest等的RequestScopeModule

更多信息http://docs.jboss.org/resteasy/docs/3.6.3.Final/userguide/html_single/index.html#Guice1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM