Java Guice:将ContainerRequestContext注入拦截器
我有一个Dropwizard应用程序,我希望能够将给定请求的Java Guice:将ContainerRequestContext注入拦截器,java,guice,dropwizard,Java,Guice,Dropwizard,我有一个Dropwizard应用程序,我希望能够将给定请求的ContainerRequestContext注入到拦截器中,基本上是这样的: 设置拦截器的GUI配置。 Provider ctxProvider=getProvider(ContainerRequestContext.class); bindInterceptor(Matchers.any()、Matchers.any()、new SecurityInterceptor(ctxProvider)); 我的拦截器看起来像: 公共类Se
ContainerRequestContext
注入到拦截器中,基本上是这样的:
设置拦截器的GUI配置。
Provider ctxProvider=getProvider(ContainerRequestContext.class);
bindInterceptor(Matchers.any()、Matchers.any()、new SecurityInterceptor(ctxProvider));
我的拦截器看起来像:
公共类SecurityInterceptor实现MethodInterceptor{
私人最终提供商ctxProvider;
公共安全拦截器(提供程序ctxProvider){
this.ctxProvider=ctxProvider;
}
@凌驾
公共对象调用(MethodInvocation MethodInvocation)抛出可丢弃的{
ContainerRequestContext ContainerRequestContext=ctxProvider.get();
//使用ctx的逻辑
返回methodInvocation.procedure();
}
}
但是,当我尝试上述操作时,我在启动时出现以下错误
1) No implementation for javax.ws.rs.container.ContainerRequestContext was bound.
如何配置Guice以便插入
ContainerRequestContext
提供程序?看起来您需要为ContainerRequestContext提供绑定为什么不使用HK2 AOP支持?它与球衣无缝配合。您在调用请求上下文时不会遇到任何问题。请检查。看起来您需要为ContainerRequestContext提供绑定。为什么不使用HK2 AOP支持呢?它与球衣无缝配合。您在调用请求上下文时不会遇到任何问题。退房