spring properties resolve 问题

在stackoverflow上看到一个问题
配置如下:
<context:property-placeholder location="/WEB-INF/application-customer-dev.properties,classpath:application-customer.properties" ignore-resource-not-found="true"/>

<import resource="classpath*:com/x/core/security/security-${login.security}.xml"/>
在application-customer.properties中有配置项:
login.security=dev
可是import却没能按照期望的发生。
解释如下:
大概spring context解析过程如下:

Basically Spring XML context setup goes more or less like this:

1、Context is created.

2、Environment is set.

3、XML is read (all XML, resolving imports if necessary). Bean definitions are created.

4、BeanFactoryPostProcessors are installed and invoked, processing bean definitions.

5、BeanPostProcessors are installed.

6、Beans are instantiated according to the bean definitions. BeanPostProcessors are applied.

PropertySourcesPlaceholderConfigurer 是一个BeanFactoryPostProcessor,这样的话,import必然发生在BeanPostProcessors 之前,也就无法解析。这是spring硬编码的,你无法改变。

原文地址:https://www.cnblogs.com/beiyeren/p/3488562.html