简体   繁体   中英

How to inject a spring bean into Jersey InjectableProvider

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM