BeanDefinitionRegistryPostProcessor를 구현한다.
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
RootBeanDefinition beanDefinition =
new RootBeanDefinition(MyServiceImpl.class); //The service implementation
serviceDefinition.setTargetType(MyService.class); //The service interface
serviceDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
registry.registerBeanDefinition("myBeanName", beanDefinition );
}
// 혹은 다음과 같은 스타일
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
for (String customerKey : customerKeys) {
String dataSourceName = "dataSource_" + customerKey;
BeanDefinitionBuilder definitionBuilder =
BeanDefinitionBuilder.genericBeanDefinition(JndiObjectFactoryBean.class);
definitionBuilder.addPropertyValue("jndiName", "jdbc/" + dataSourceName);
registry.registerBeanDefinition(dataSourceName, definitionBuilder.getBeanDefinition());
}
}