diff --git a/src/main/java/org/springframework/guice/annotation/ModuleRegistryConfiguration.java b/src/main/java/org/springframework/guice/annotation/ModuleRegistryConfiguration.java index 32e0143..545cfe4 100644 --- a/src/main/java/org/springframework/guice/annotation/ModuleRegistryConfiguration.java +++ b/src/main/java/org/springframework/guice/annotation/ModuleRegistryConfiguration.java @@ -65,7 +65,8 @@ import org.springframework.guice.module.SpringModule; */ @Configuration @Order(Ordered.HIGHEST_PRECEDENCE) -class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor, ApplicationContextAware { +class ModuleRegistryConfiguration + implements BeanDefinitionRegistryPostProcessor, ApplicationContextAware { private static final String SPRING_GUICE_DEDUPE_BINDINGS_PROPERTY_NAME = "spring.guice.dedup"; private ApplicationContext applicationContext; @@ -140,7 +141,8 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor String valueAttribute = getValueAttributeForNamed(key.getAnnotation()); if (valueAttribute != null) { return valueAttribute + "_" + className; - } else { + } + else { return className; } } @@ -148,9 +150,11 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor private String getValueAttributeForNamed(Annotation annotation) { if (annotation instanceof Named) { return ((Named) annotation).value(); - } else if (annotation instanceof javax.inject.Named) { + } + else if (annotation instanceof javax.inject.Named) { return ((javax.inject.Named) annotation).value(); - } else { + } + else { return null; } } @@ -160,7 +164,7 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor throws BeansException { modules = new ArrayList(((ConfigurableListableBeanFactory) registry) .getBeansOfType(Module.class).values()); - modules.add(new SpringModule(this.applicationContext)); + modules.add(new SpringModule((ConfigurableListableBeanFactory) registry)); Map, Binding> bindings = new HashMap, Binding>(); List elements = Elements.getElements(Stage.TOOL, modules); if (applicationContext.getEnvironment().getProperty( @@ -253,20 +257,23 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - beanFactory.registerSingleton("guiceInjectorInitializer", new GuiceInjectorInitializingBeanPostProcessor(){ - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if(injectorCreated.compareAndSet(false,true)) { - createInjector(modules, beanFactory); - } - return bean; - } - }); + beanFactory.registerSingleton("guiceInjectorInitializer", + new GuiceInjectorInitializingBeanPostProcessor() { + @Override + public Object postProcessBeforeInitialization(Object bean, + String beanName) throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, + String beanName) throws BeansException { + if (injectorCreated.compareAndSet(false, true)) { + createInjector(modules, beanFactory); + } + return bean; + } + }); } @Override @@ -274,14 +281,12 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor throws BeansException { this.applicationContext = applicationContext; } - - private static class GuiceInjectorInitializingBeanPostProcessor implements BeanPostProcessor, Ordered { + + private static class GuiceInjectorInitializingBeanPostProcessor + implements BeanPostProcessor, Ordered { @Override public int getOrder() { return Ordered.LOWEST_PRECEDENCE - 1; } } } - - - diff --git a/src/main/java/org/springframework/guice/module/BeanFactoryProvider.java b/src/main/java/org/springframework/guice/module/BeanFactoryProvider.java index ef0ee32..ca2a474 100644 --- a/src/main/java/org/springframework/guice/module/BeanFactoryProvider.java +++ b/src/main/java/org/springframework/guice/module/BeanFactoryProvider.java @@ -25,6 +25,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.inject.Provider; +import com.google.inject.spi.ProvisionListener; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -34,27 +36,26 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.OrderComparator; -import com.google.inject.spi.ProvisionListener; - /** *

- * A {@link Provider} for a {@link BeanFactory} from an - * {@link ApplicationContext} that will not be refreshed until the Guice - * injector wants to resolve dependencies. Delaying the refresh means that the - * bean factory can resolve dependencies from Guice modules (and vice versa). + * A {@link Provider} for a {@link BeanFactory} from an {@link ApplicationContext} that + * will not be refreshed until the Guice injector wants to resolve dependencies. Delaying + * the refresh means that the bean factory can resolve dependencies from Guice modules + * (and vice versa). *

*

- * Also implements {@link Closeable} so if you want to clean up resources used - * in the application context then you can keep a reference to the provider and - * call {@link #close()} on it when the application is shut down. Alternatively, - * you could register an {@link ApplicationContextInitializer} that sets a - * shutdown hook, so that the context is closed automatically when the JVM ends. + * Also implements {@link Closeable} so if you want to clean up resources used in the + * application context then you can keep a reference to the provider and call + * {@link #close()} on it when the application is shut down. Alternatively, you could + * register an {@link ApplicationContextInitializer} that sets a shutdown hook, so that + * the context is closed automatically when the JVM ends. *

* * @author Dave Syer * */ -public class BeanFactoryProvider implements Provider, Closeable { +public class BeanFactoryProvider + implements Provider, Closeable { private Class[] config; private String[] basePackages; @@ -130,17 +131,21 @@ public class BeanFactoryProvider implements Provider new MyService()); + } + + } + +}