I have two projects, one of them (Services) includes the second one (Core). I've defined this PropertyPlaceholderConfigurer below within Core project:
<bean id="propertyConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:appConfig.properties</value>
</list>
</property>
</bean>
And I want to extend the Core placeholder in the upper project, including appConfig.properties and some other ones. The only way I found is to define another different bean (different ID) in the upper level and include the new ones:
<bean id="servicesPropertyConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:swagger.properties</value>
</list>
</property>
</bean>
But it yields it cannot find appConfig.properties, I guess it's only using one of these PropertyPlaceholderConfigurer at the same time? Is it necesary to specify all resources in the upper propertyConfigurer?:
<bean id="servicesPropertyConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:swagger.properties</value>
<value>classpath:appConfig.properties</value>
</list>
</property>
</bean>
Is it posible to extend the Core bean o use both at the same time?
You can use multiple at the same time BUT you have to have different names/ids for each else one will override the other. Next to that you need to either use different placeholders (${...}) for each or configure it to ignore unresolved placeholders.
Instead of using the class definition I strongly suggest yo use the namespace (<context:property-placeholder .. />
which saves you some xml. (It will generate beans with unique names so you can have multiple at the same time, make sure to set the ignore-unresolvable
attribute to true
.
As a last resort you could implement your a BeanDefinitionRegistryPostProcessor
which detects all PropertyPlaceHolderConfigurer
instances, merges them into one and move all the locations/resources to the merged one. That way you don't have to worry about multiple different placeholders or unresolvable properties.
try this code
<bean id="servicesPropertyConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:swagger.properties</value>
<value>classpath:appConfig.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With