Multiple Spring PropertyPlaceholderConfigurer at the same time

后端 未结 2 605
暖寄归人
暖寄归人 2021-01-18 16:04

I have two projects, one of them (Services) includes the second one (Core). I\'ve defined this PropertyPlaceholderConfigurer below within Core project:

<         


        
相关标签:
2条回答
  • 2021-01-18 16:49

    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.

    0 讨论(0)
  • 2021-01-18 17:00

    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"/>
    

    0 讨论(0)
提交回复
热议问题