Add support for @Named beans in SpringModule
A SpringModule now registers all beans by type and by name separately, so clients can inject qualified instances.
This commit is contained in:
@@ -34,7 +34,9 @@ import org.springframework.guice.module.SpringModule;
|
||||
import com.google.inject.ConfigurationException;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -64,6 +66,12 @@ public class SpringModuleMetadataTests {
|
||||
assertNotNull(injector.getInstance(Service.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoServicesByName() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MoreConfig.class);
|
||||
assertNotNull(injector.getInstance(Key.get(Service.class, Names.named("service"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includes() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataIncludesConfig.class);
|
||||
|
||||
Reference in New Issue
Block a user