0

I have two beans indCartStrategy and usCartStrategy, with different id but the same class and different parameter values. I am aliasing both of them to the same alias. Instead of calling my later alias id it is still calling the former bean, not the one that I have declared.

    <alias name="indCartStrategy" alias="cartStrategy"/>
<bean id="indCartStrategy" parent="defaultCartStrategy" class="com.strategy.impl.USCartStrategyImpl">
    <property name="cartValidators">
        <map key-type="com.validation.USCartValidationType">
            <entry key="CART_PAGE">
                <list value-type="com.validation.USCartValidator">
                    <bean class="com.validation.impl.USValidator2"/>
                </list>
            </entry>
        </map>
    </property>
</bean>





<alias name="usCartStrategy" alias="cartStrategy"/>
<bean id="usCartStrategy" parent="defaultCartStrategy" class="com.strategy.impl.USCartStrategyImpl">
    <property name="cartValidators">
        <map key-type="com.validation.USCartValidationType">
            <entry key="CART_PAGE">
                <list value-type="com.validation.USCartValidator">
                    <bean class="com.validation.impl.USValidator1"/>
                    <bean class="com.validation.impl.USValidator2"/>
                </list>
            </entry>
        </map>
    </property>
</bean>

In my bean i.e. indCartStrategy USValidator1 is not getting called still when I am calling cartStrategy both the validators i.e. USValidator1 and USValidator2 are getting called.

Farrukh Chishti
  • 7,652
  • 10
  • 36
  • 60
  • 1
    Any specific reason why you're trying to have the same alias for different beans? If the purpose is to have two implementations of the same base interface, maybe you can use different "name" attributes for each bean, and use the @Qualifier attribute to choose the required implementation inside anigher bean. – Daud Nov 25 '18 at 12:23
  • 1
    @Daud : The original usCartStrategy cannot be modified as it from an API so I can only change my implementation i.e. indCartStrategy – Farrukh Chishti Nov 26 '18 at 03:36
  • 1
    Maybe this would be helpful: https://stackoverflow.com/questions/10534053/autowiring-two-beans-implementing-same-interface-how-to-set-default-bean-to-au (no need to use @Primary) – Daud Nov 26 '18 at 06:31

0 Answers0