Announcement Announcement Module
Collapse
No announcement yet.
Bean alias override? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean alias override?

    [Spring 1.2.4]

    I have a context definition containing:

    <bean id="b1" class="...">

    <alias name="b1" alias="a1"/>
    <alias name="b1" alias="a2"/>

    In another application context file I want to override alias a2 to to refer to another bean b2 (same way I would override beans).

    <alias name="b2" alias="a1"/>

    This will fail with:

    org.springframework.beans.factory.BeanDefinitionSt oreException: Cannot register alias 'a1' for bean name 'b2': it's already registered for bean name 'b1'

    Is there an alternative way to do this without changing bean b1 and references to a2 or a1. The idea is to replace (a2,b1) with (a2,b2) without impacting other consumers of a2 or b1. Presumably I will have ti shelf the idea of using the alias tag and use some form of factory bean to work around this limitation?

    Are there plans to address this in future versions or are alias definitions considered final for other reasons?

    I also run into the issue of alias tag not supporting token replacement:

    <alias name="${beanname}" alias="a1"/>

    does not work, the property reference is not expanded by the property configurer.

  • #2
    Solution:

    Code:
    <bean id="b1" class="...">
    
    <bean parent="b1" id="a1"/> 
    <bean parent="b1" id="a2"/>
    In another application context file:

    Code:
    <bean parent="b2" id="a1"/>

    Comment

    Working...
    X