启动类:
ApplicationContext ac = new ClassPathXmlApplicationContext("spring-${username}.xml");
Person bean = ac.getBean(Person.class);
调用链路如下:
parseStringValue:130, PropertyPlaceholderHelper (org.springframework.util)
replacePlaceholders:124, PropertyPlaceholderHelper (org.springframework.util)
doResolvePlaceholders:245, AbstractPropertyResolver (org.springframework.core.env)
resolveRequiredPlaceholders:210, AbstractPropertyResolver (org.springframework.core.env)
resolveRequiredPlaceholders:571, AbstractEnvironment (org.springframework.core.env)
resolvePath:131, AbstractRefreshableConfigApplicationContext (org.springframework.context.support)
setConfigLocations:86, AbstractRefreshableConfigApplicationContext (org.springframework.context.support)
:148, ClassPathXmlApplicationContext (org.springframework.context.support)
:87, ClassPathXmlApplicationContext (org.springframework.context.support)
main:78, Test (com.mashibing)
在这个方法里调用解析占位符的处理:
这里key就是username;
这个属性有username字段,为ASUS,解析后返回的文件名如下: