カスタムBeanDefinitionRegistryPostProcessor登録bean
2197 ワード
カスタムBeanDefinitionRegistryPostProcessor
概要
使用
public class CustomBeanDefinitionRegistry implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
}
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
RootBeanDefinition helloBean = new RootBeanDefinition(Hello.class);
// Bean
registry.registerBeanDefinition("hello", helloBean);
}
}
// , @Bean
@Configuration
public class SpringConfiguration {
@Bean
public CustomBeanDefinitionRegistry customBeanDefinitionRegistry() {
return new CustomBeanDefinitionRegistry();
}
}
// , @Component
@Component
public class CustomizeBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
//
Utils.printTrack("execute postProcessBeanDefinitionRegistry");
// bean ,bean CalculateServiceImpl
RootBeanDefinition helloBean = new RootBeanDefinition(CalculateServiceImpl.class);
//bean spring
beanDefinitionRegistry.registerBeanDefinition("calculateService", helloBean);
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
//
Utils.printTrack("execute postProcessBeanFactory");
}
}