Spring 占位符解析器的作用 - PropertyPlaceholderHelper

在Spring的众多功能中,有一个帮助类PropertyPlaceholderHelper,专门负责解析路径中或者名字中含有占位符的字串,并负责填充上具体的值。

	public String replacePlaceholders(String value, final Properties properties) {
		Assert.notNull(properties, "Argument 'properties' must not be null.");
		return replacePlaceholders(value, new PlaceholderResolver() {
			public String resolvePlaceholder(String placeholderName) {
				return properties.getProperty(placeholderName);
			}
		});
	}


例举一个例子:

	public static void main(String[] args) throws Exception {
		Properties p = System.getProperties();
		p.setProperty("name", "be");
		ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:${name}ans.xml");
		LoggingBean lb = (LoggingBean) factory.getBean("logging");
		lb.run();
		BeanDestried sd = (BeanDestried)factory.getBean("beanDestried");
		sd.run();
		//print();
	}

这样占位符就换成了 我们想要的内容。其实在真正的配置文件中,此种问题很普遍,但是归根结底,还是需要这个帮助类来处理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值