简体   繁体   中英

Spring declaration for interfaces with the same implementation

I have a problem with Spring.

I have two separate interfaces, findUnconditionalDiscountValuesStrategy and findConditionalDiscountValuesStrategy. These interfaces are implemented in the same class MmfgFindPricingWithCurrentPriceFactoryStrategy.

This is declared in the spring configuration file like this:

<alias name="mmfgFindPricingWithCurrentPriceFactoryStrategy" alias="currentFactoryFindPricingStrategy"/>
<bean id="mmfgFindPricingWithCurrentPriceFactoryStrategy" class="com.mmfg.mmfgacceleratorcore.order.strategies.calculation.impl.MmfgFindPricingWithCurrentPriceFactoryStrategy" parent="abstractBusinessService">
    <property name="findPricingWithCurrentPriceFactoryStrategy" ref="original-currentFactoryFindPricingStrategy"/>
    <property name="configurationService" ref="configurationService"/>
    <property name="mmfgSessionService" ref="mmfgSessionService"/>
    <property name="mmfgUtilsDao" ref="mmfgUtilsDao" />
</bean>

Now, I use the two interfaces in a class

private FindUnconditionalDiscountValuesStrategy findUnconditionalDiscountValuesStrategy;
private FindConditionalDiscountValuesStrategy findConditionalDiscountValueStrategy;

with getter and setter (getter protected and setter @Required ).

Now I have declared this class in this way in the spring configuration file:

<bean id="mmfgOrderCalculationStrategy" class="com.mmfg.mmfgacceleratorcore.order.strategies.calculation.impl.DefaultMmfgOrderCalculationStrategy">
    <property name="findUnconditionalDiscountValuesStrategy" ref="currentFactoryFindPricingStrategy"/>
    <property name="findConditionalDiscountValuesStrategy" ref="currentFactoryFindPricingStrategy"/>
    <property name="modelService" ref="modelService" />
    <property name="commonI18NService" ref="commonI18NService" />
    <property name="calculationService" ref="calculationService"/>
</bean>

the ref is the same for the two interfaces, because the implementation class is the same.

But at runtime I obtain this error:

org.springframework.beans.factory.BeanInitializationException: Property 'findConditionalDiscountValueStrategy' is required for bean 'mmfgOrderCalculationStrategy'

How I have to declare the ref in the two properties?

There is a typo error. My property is called findConditionalDiscount Value Strategy . But in the class the name is findConditionalDiscount Values Strategy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM