Switch to supplier for one bean definition
This commit is contained in:
@@ -38,7 +38,6 @@ class GuiceFactoryBean<T> implements FactoryBean<T> {
|
||||
|
||||
private final boolean isSingleton;
|
||||
|
||||
@Autowired
|
||||
private Injector injector;
|
||||
|
||||
GuiceFactoryBean(Class<T> beanType, Key<T> key, boolean isSingleton) {
|
||||
@@ -47,6 +46,11 @@ class GuiceFactoryBean<T> implements FactoryBean<T> {
|
||||
this.isSingleton = isSingleton;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
void setInjector(Injector injector) {
|
||||
this.injector = injector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getObject() throws Exception {
|
||||
return (T) this.injector.getInstance(this.key);
|
||||
|
||||
@@ -160,10 +160,10 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor
|
||||
|
||||
// Register the injector initializer
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(GuiceInjectorInitializer.class);
|
||||
ConstructorArgumentValues args = new ConstructorArgumentValues();
|
||||
args.addIndexedArgumentValue(0, modules);
|
||||
args.addIndexedArgumentValue(1, this.applicationContext);
|
||||
beanDefinition.setConstructorArgumentValues(args);
|
||||
final List<Module> finalModules = new ArrayList<>(modules);
|
||||
beanDefinition.setInstanceSupplier(() -> new GuiceInjectorInitializer(finalModules,
|
||||
(ConfigurableApplicationContext) this.applicationContext));
|
||||
beanDefinition.setAttribute(SpringModule.SPRING_GUICE_SOURCE, true);
|
||||
registry.registerBeanDefinition("guiceInjectorInitializer", beanDefinition);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user