Multiple Spring PropertyPlaceholderConfigurer at the same time

后端 未结 2 632
暖寄归人
暖寄归人 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 ( 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.

提交回复
热议问题