如何将 spring bean 注入 Jersey InjectableProvider
我刚刚为 Jersey 创建了一个 InjectableProvider 的实现,但我发现要完整设置可注入,我需要 Spring 工厂 bean 的支持。我正在寻找一种方法将该工厂作为字段注入到提供程序类中。我已经尝试使用 @Component 注释,但是失败并出现 IllegalState 异常(没有为范围“请求”注册范围))
处理该问题的正确方法是什么?或者有没有办法从 Jerseys HTTPcontext 检索应用程序上下文?
I have just created an implementation of an InjectableProvider for Jersey, but I found to completeley setup the injectable I need support from a Spring factory bean. I'm looking for a way to inject that factory as a field into the provider class. I tried already using the @Component annotation, but tha failed with an IllegalState exception (No Scope registered for scope 'request'))
What is the proper way to handle that? Or is there a way to reteive the application context from Jerseys HTTPcontext?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然已经晚了,但我讨厌看到问题没有得到解答。
通常,在你的工厂 bean 上你应该有:
在你的提供者中,你应该使用
首先想到的,你会认为你应该使用 @Autowired 因为它是 Spring 的“组件” - 但由于我们在 Jersey 实例化 bean 中连接它,应该使用 Jersey 的@InjectParam。
This is way late, but I hate seeing questions unanswered.
typically, on your factory bean you should have:
and in your provider, you should use
On first thought, you would think you should use @Autowired since it's Spring's "Component" - but since we're wiring it in a Jersey instantiated bean, Jersey's @InjectParam should be used.