开发者

How to inject a spring bean into Jersey InjectableProvider

开发者 https://www.devze.com 2023-03-31 15:22 出处:网络
I have just created an implementation of an InjectableProvider for Jersey, but I found to completeley setup the injectable I need support fr开发者_Go百科om a Spring factory bean. I\'m looking for a wa

I have just created an implementation of an InjectableProvider for Jersey, but I found to completeley setup the injectable I need support fr开发者_Go百科om 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?


This is way late, but I hate seeing questions unanswered.

typically, on your factory bean you should have:

@Component
public class FactoryBean(){}

and in your provider, you should use

public class Provider extends InjectableProvider<Context>{
      @InjectParam
      private FactoryBean factoryBean;
}

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号