Issue
I am creating multiple bean instances of a class with different property values in spring configuration. For example:
<bean id="myBeanA" class="MyClass">
<property name="identifier" value="A"/>
</bean>
<bean id="myBeanY" class="MyClass">
<property name="identifier" value="B"/>
</bean>
I am new to Spring framework and I am just curious to know the pros and cons to doing this.
Solution
of course you can (as you already show - ignoring typo). Pros/Cons? None, you just do it if it make sense for you...
<bean id="primaryService" class="MyService">
<property name="url" value="http://domain1/"/>
</bean>
<bean id="premiumService" class="MyService">
<property name="url" value="http://domain2/"/>
</bean>
E.g. you can have two instances of the same service type, but accessing different remote URL. You can use premiumService
only for paying customers as kind of quality of service (e.g. domain2
is stronger machine)
Answered By - sodik
Answer Checked By - Gilberto Lyons (JavaFixing Admin)