Programatically Add a AnnotationSessionFactoryBean

Posted by user146714 on Stack Overflow See other posts from Stack Overflow or by user146714
Published on 2010-12-28T01:09:11Z Indexed on 2010/12/28 1:54 UTC
Read the original article Hit count: 236

Filed under:
|
|

Hi,

I have a class that implements BeanDefinitionRegistryPostProcessor.

I am trying to add an AnnotationSessionFactoryBean to my Spring Context in either postProcessBeanFactory or postProcessBeanDefinitionRegistry. I need to do this programatically so that I can configure the object at runtime.

I am trying to do:

@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);

thanks for your help

--updated with solution:

had to do a:

    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(AnnotationSessionFactoryBean.class);
    bd.getPropertyValues().add("dataSource", dataSource);
            bdr.registerBeanDefinition("sessionFactory", bd);

© Stack Overflow or respective owner

Related posts about java

Related posts about spring