BeanDefinitionRegistryPostProcessor를 구현하는 클래스가 있습니다.프로그래밍 방식으로 AnnotationSessionFactoryBean 추가
postProcessBeanFactory 또는 postProcessBeanDefinitionRegistry에서 Spring 컨텍스트에 AnnotationSessionFactoryBean을 추가하려고합니다. 런타임에 객체를 구성 할 수 있도록 프로그래밍 방식으로이 작업을 수행해야합니다.
내가 할 노력하고 있어요 : 당신의 도움에 대한
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry bdr) throws BeansException {
RootBeanDefinition bd = new RootBeanDefinition(
AnnotationSessionFactoryBean.class);
// fails here.. can not cast
AnnotationSessionFactoryBean asfb = (AnnotationSessionFactoryBean)bd;
bdr.registerBeanDefinition("sessionFactory", asfb);
감사
이 솔루션 --updated :
GenericBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(AnnotationSessionFactoryBean.class);
bd.getPropertyValues().add("dataSource", dataSource);
bdr.registerBeanDefinition("sessionFactory", bd);