Reputation: 183
Lets say I have the following property files:
service.properties service1.properties service2.properties
My application would be making a bunch of service calls and will be using the default property file (service.properties). However, I would like to override it with service1.properties when service1 is making the call. Similarly service2.properties should override for service2 call.
For the rest of the service calls I would still like to use service.properties.
Any pointers as to how I should go about doing this.
Upvotes: 0
Views: 837
Reputation: 5659
<bean id="service" class="com.concept.testing.Service">
<property name="url" value="${url.property}" />
<property name="user" value="${user.property}" />
<property name="password" value="password" />
<property name="app" value="Application" />
</bean>
Your scenario make sense to me only above scenario, where you want to say use a method of class Service whose few properties are constant and few need to be injected dynamically from a property file. Since the class is same for all the service calls so you do not want to define the different properties and beans for service1 and service2.
So here you can use the configuration inheritance in spring which can be defined like below :
<bean id="service1" parent="service">
<property name="url" value="${url1.property}" />
<property name="user" value="${user1.property}" />
</bean>
<bean id="service2" parent="service">
<property name="url" value="${url2.property}" />
<property name="user" value="${user2.property}" />
</bean>
So now you can inject the service1 bean for service1 call and service2 bean for service2 call. Their parent class is same but the only difference is in their configuration (i.e. url and name).
Upvotes: 1