在*上看到一个问题
配置如下:
<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、BeanFactoryPostProcessor
s are installed and invoked, processing bean definitions.
5、BeanPostProcessor
s are installed.
6、Beans are instantiated according to the bean definitions. BeanPostProcessors are applied.
而PropertySourcesPlaceholderConfigurer
是一个BeanFactoryPostProcessor,这样的话,import必然发生在
BeanPostProcessor
s 之前,也就无法解析。这是spring硬编码的,你无法改变。