remove check for Tool stage from SpringModule as it is no longer required

This commit is contained in:
Taylor Wicksell
2018-03-01 05:00:41 -06:00
committed by Dave Syer
parent 8cbdf37570
commit 5e3603c29d
2 changed files with 31 additions and 18 deletions

View File

@@ -72,24 +72,22 @@ public class SpringModule extends AbstractModule {
@Override
public void configure() {
if (binder().currentStage() != Stage.TOOL) {
if (beanFactory == null) {
beanFactory = beanFactoryProvider.get();
}
if (beanFactory.getBeanNamesForType(ProvisionListener.class).length > 0) {
binder().bindListener(Matchers.any(),
beanFactory.getBeansOfType(ProvisionListener.class).values()
.toArray(new ProvisionListener[0]));
}
if (beanFactory instanceof DefaultListableBeanFactory) {
((DefaultListableBeanFactory) beanFactory)
.setAutowireCandidateResolver(new GuiceAutowireCandidateResolver(
binder().getProvider(Injector.class)));
}
if (beanFactory.getBeanNamesForType(GuiceModuleMetadata.class).length > 0) {
this.matcher = new CompositeTypeMatcher(
beanFactory.getBeansOfType(GuiceModuleMetadata.class).values());
}
if (beanFactory == null) {
beanFactory = beanFactoryProvider.get();
}
if (beanFactory.getBeanNamesForType(ProvisionListener.class).length > 0) {
binder().bindListener(Matchers.any(),
beanFactory.getBeansOfType(ProvisionListener.class).values()
.toArray(new ProvisionListener[0]));
}
if (beanFactory instanceof DefaultListableBeanFactory) {
((DefaultListableBeanFactory) beanFactory)
.setAutowireCandidateResolver(new GuiceAutowireCandidateResolver(
binder().getProvider(Injector.class)));
}
if (beanFactory.getBeanNamesForType(GuiceModuleMetadata.class).length > 0) {
this.matcher = new CompositeTypeMatcher(
beanFactory.getBeansOfType(GuiceModuleMetadata.class).values());
}
bind(beanFactory);
}

View File

@@ -19,6 +19,7 @@ import javax.inject.Named;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +37,11 @@ import static org.junit.Assert.assertNotNull;
*/
public class EnableGuiceModulesTests {
@After
public void cleanUp() {
System.clearProperty("spring.guice.dedup");
}
@Test
public void test() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
@@ -43,6 +49,15 @@ public class EnableGuiceModulesTests {
assertNotNull(context.getBean(Foo.class));
context.close();
}
@Test
public void testWithDedupFeatureEnabled() {
System.setProperty("spring.guice.dedup", "true");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
TestConfig.class);
assertNotNull(context.getBean(Foo.class));
context.close();
}
@Test
public void module() {