Announcement Announcement Module
Collapse
No announcement yet.
Resolving bean aliases? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolving bean aliases?

    I have a BeanFactoryPostProcessor that injects the EJB3 @Entity classes into the hibernate SessionFactory's BeanDefinition prior to it being instantiated. In postProcessBeanFactory() I obtain the BeanDefinition:

    Code:
    BeanDefinition sessionFactoryBeanDefinition =
        beanFactory.getBeanDefinition(sessionFactoryBeanName);
    But the name contained by the variable sessionFactoryBeanName -- "persistence.sessionFactory" in this case -- is an alias:

    Code:
    <alias name="persistence.spi.sessionFactory" 
        alias="persistence.sessionFactory"/>
    DefaultListableBeanFactory.getBeanDefinition(Strin g beanName) does not attemp to resolve alias names, and hence I get a NoSuchBeanDefinitionException exception.

    I am getting around this via a priviledged aspect that intercepts the calls to getBeanDefinition and uses transformedBeanName(String name) to resolve the alias. This kinda sucks. I would think that getBeanDefinition should handle this.

    Is there some other way to handle alias when tweaking BeanDefintions, or should I file an jira issue?

    thanks!

  • #2
    Well, I simply changed my post-processor to do:

    Code:
        BeanDefinition sessionFactoryBeanDefinition = 
            ((AbstractBeanFactory) beanFactory).getMergedBeanDefinition(sessionFactoryBeanName);
    And that did the trick. Would this the presribed method for getting a BeanDefinition using an alias?

    Comment

    Working...
    X