【发布时间】:2019-07-16 17:12:12
【问题描述】:
我有一个网络应用程序正在从泽西岛移植到 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();
}
}
所有这些WebApplication、HttpContext 等类都是针对泽西岛的。问题是如何在 RestEasy 下提供类似的东西。
一个尝试是这样的
public class MyServlet extends ServletModule {
@Provides @RequestScoped
public UriInfo getUriInfo(@Context UriInfo info) {
return info;
}
}
但这会导致 Guice 的注入代码中的堆栈溢出。
我知道@Context 属性应该让我在 RestEasy 下注入 UriInfo,但我不知道在 Guice 提供程序中使用它。
该应用将部署在 Wildfly 15 上。
非常感谢任何帮助,因为这让我头晕目眩。
【问题讨论】:
标签: java dependency-injection jersey guice resteasy