BeanPostProcessor
보다 먼저 실행된다.@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()); } }
postProcessBeanFactory
는 필요없을 경우 구현하지 않고 빈 메소드로 남겨둔다.@Configuration
으로 지정하거나 그냥 @Bean
으로 생성하는 것은 작동하지 않는다.