Created
April 29, 2014 17:00
-
-
Save dwelch2344/11406133 to your computer and use it in GitHub Desktop.
While reading a few great articles (http://www.intertech.com/Blog/spring-4-generic-qualifiers/ comes to mind) I noticed that Spring 4 supports injecting generic objects if their type is provided when defining @beans. I'm trying to figure out how I can do that when describing beans in a BeanDefinitionRegistryPostProcessor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Consumer{ | |
// these work with qualifiers... | |
@Inject | |
private GenericService<User, Long> userService; | |
@Inject | |
private GenericService<Organization, Long> orgService; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenericService<E, ID>{ | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Processor extends InstantiationAwareBeanPostProcessorAdapter | |
implements BeanDefinitionRegistryPostProcessor{ | |
// ... | |
@Override | |
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry r) throws BeansException { | |
AbstractBeanDefinition service = BeanDefinitionBuilder.rootBeanDefinition(GenericService.class) | |
.getBeanDefinition(); | |
r.registerBeanDefinition(service, "userService" ); | |
// how do I hint that this bean has the bound types <User, Long> ?? | |
AbstractBeanDefinition service2 = BeanDefinitionBuilder.rootBeanDefinition(GenericService.class) | |
.getBeanDefinition(); | |
// how do I hint that this bean has the bound types <Organization, Long> ?? | |
r.registerBeanDefinition(service2, "orgService" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment