use of org.jvnet.hk2.spring.bridge.api.SpringIntoHK2Bridge in project jersey by jersey.
the class SpringComponentProvider method initialize.
@Override
public void initialize(InjectionManager injectionManager) {
this.injectionManager = injectionManager;
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(LocalizationMessages.CTX_LOOKUP_STARTED());
}
ServletContext sc = injectionManager.getInstance(ServletContext.class);
if (sc != null) {
// servlet container
ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
} else {
// non-servlet container
ctx = createSpringContext();
}
if (ctx == null) {
LOGGER.severe(LocalizationMessages.CTX_LOOKUP_FAILED());
return;
}
LOGGER.config(LocalizationMessages.CTX_LOOKUP_SUCESSFUL());
// initialize HK2 spring-bridge
HK2InjectionManager hk2InjectionManager = (HK2InjectionManager) injectionManager;
SpringBridge.getSpringBridge().initializeSpringBridge(hk2InjectionManager.getServiceLocator());
SpringIntoHK2Bridge springBridge = injectionManager.getInstance(SpringIntoHK2Bridge.class);
springBridge.bridgeSpringBeanFactory(ctx);
// register Spring @Autowired annotation handler with HK2 ServiceLocator
Binder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(new AutowiredInjectResolver(ctx)).to(InjectionResolver.class);
bind(ctx).to(ApplicationContext.class).named("SpringContext");
}
};
injectionManager.register(binder);
LOGGER.config(LocalizationMessages.SPRING_COMPONENT_PROVIDER_INITIALIZED());
}
Aggregations