现在还没有完全验证好,有空看看报错信息

https://www.cnblogs.com/fanguangdexiaoyuer/p/5788432.html

1.目录结构

  

2.

 package cn.caojun.properties;

 import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.util.PropertyPlaceholderHelper;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties; public class CustomPropertyConfigurer extends PropertyPlaceholderConfigurer {
private static Map<String,String> properties = new HashMap<String,String>();
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
// cache the properties
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false);
for(Map.Entry<Object,Object> entry:props.entrySet()){
String stringKey = String.valueOf(entry.getKey());
String stringValue = String.valueOf(entry.getValue());
//用属性文件键值属性props替换字符串stringValue
stringValue = helper.replacePlaceholders(stringValue, props);
properties.put(stringKey, stringValue);
}
super.processProperties(beanFactoryToProcess, props);
} public static Map<String, String> getProperties() {
return properties;
} public static String getProperty(String key){
return properties.get(key);
}
}

3.property

 site=iteye
blog=antlove
url=${site}/${blog}

4.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="SpringDemo" class="cn.caojun.spring.SpringDemo"></bean>
<bean id="propertyConfigurer" class="cn.caojun.properties.CustomPropertyConfigurer">
<property name="locations">
<list>
<value>classpath:cn/caojun/properties/project.properties</value>
</list>
</property>
</bean>
</beans>

5.Main

 package cn.caojun.properties;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.Map; public class Main {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
CustomPropertyConfigurer customPropertyConfigurer=(CustomPropertyConfigurer)applicationContext.getBean("propertyConfigurer");
Map<String,String> properties = customPropertyConfigurer.getProperties();
System.out.println(properties);
}
}

关于replacePlaceholders的更多相关文章

  1. SPRING多个占位符配置文件解析源码研究--转

    原文地址:http://www.cnphp6.com/archives/85639 Spring配置文件: <context:property-placeholder location=&quo ...

  2. Spring源码学习-PropertyPlaceholderHelper

    转载:http://my.oschina.net/ydsakyclguozi/blog/465526 1. CustomPropertyConfigurer.java package property ...

  3. spring源码解析(一)---占位符解析替换

    一.结构类图 ①.PropertyResolver : Environment的顶层接口,主要提供属性检索和解析带占位符的文本.bean.xml配置中的所有占位符例如${}都由它解析 ②.Config ...

  4. Circular placeholder reference 'server.port' in property definitions

    Exception in thread "main" java.lang.IllegalArgumentException: Circular placeholder refere ...

  5. Circular placeholder reference 'jdbc.driver' in property definitions

    Caused by: java.lang.IllegalArgumentException: Circular placeholder reference 'jdbc.driver' in prope ...

  6. 【ES】ElasticSearch初体验之使用Java进行最基本的增删改查~

    好久没写博文了, 最近项目中使用到了ElaticSearch相关的一些内容, 刚好自己也来做个总结. 现在自己也只能算得上入门, 总结下自己在工作中使用Java操作ES的一些小经验吧. 本文总共分为三 ...

  7. 【Spring源码分析】.properties文件读取及占位符${...}替换源码解析

    前言 我们在开发中常遇到一种场景,Bean里面有一些参数是比较固定的,这种时候通常会采用配置的方式,将这些参数配置在.properties文件中,然后在Bean实例化的时候通过Spring将这些.pr ...

  8. SpringSecurityOauth RCE (CVE-2016-4977) 分析与复现

    目录 0x00 前言 0x01 调试分析 0x02 补丁分析 0x03 参考 影响版本: 2.0.0-2.0.9 1.0.0-1.0.5 0x00 前言 这个漏洞与之前那个SpringBoot的SpE ...

  9. SpringBoot SpEL表达式注入漏洞-分析与复现

    目录 0x00前言 0x01触发原因 0x02调试分析 0x03补丁分析 0x04参考文章 影响版本: 1.1.0-1.1.12 1.2.0-1.2.7 1.3.0 修复方案:升至1.3.1或以上版本 ...

随机推荐

  1. HGOI20181031 模拟题解

    sol:第一题就DP?!然后写了O(n^2) dp再考虑优化!!!(尽量部分分带上!!!) 我写了正确的dp然后优化错了,具体的dp方法是考虑到对于右侧到左侧他是没有后效性的 所以定义f[i]为i及以 ...

  2. 【bzoj4676】 两双手

    http://www.lydsy.com/JudgeOnline/problem.php?id=4767 (题目链接) 题意 求在网格图上从$(0,0)$走到$(n,m)$,其中不经过一些点的路径方案 ...

  3. k8s role

    转  https://blog.qikqiak.com/post/add-authorization-for-kubernetes-dashboard/ 另外还可以参考这个  https://mrit ...

  4. ELK logstash 处理MySQL慢查询日志

    在生产环境下,logstash 经常会遇到处理多种格式的日志,不同的日志格式,解析方法不同.下面来说说logstash处理多行日志的例子,对MySQL慢查询日志进行分析,这个经常遇到过,网络上疑问也很 ...

  5. for in,Object.keys和Object.getOwnPropertyNames的区别

    var parent = Object.create(Object.prototype, { a: { value: 1, writable: true, enumerable: true, conf ...

  6. POJ-1459 Power Network(最大流)

    https://vjudge.net/problem/POJ-1459 题解转载自:優YoU http://user.qzone.qq.com/289065406/blog/1299339754 解题 ...

  7. [转载]win7休眠后网络断开怎么办?如何设置?

    http://jingyan.baidu.com/article/8065f87fc87d0423312498af.html 有时会遇到在Windows7系统休眠模式下会自动断开网络连接,唤醒系统也是 ...

  8. c# 防止sql注入对拼接sql脚本的各个参数处理

    调用方法:GameServerId = this.NoHtml(GameServerId);//GameServerId为一个拼接sql的参数 /// <summary> /// 过滤标记 ...

  9. perl6 中将 字符串 转成十六进制

    say Blob.new('abcde'.encode('utf8')).unpack("H*"); say '0x'~'abcde'.encode('utf8').unpack( ...

  10. linux服务器如何添加sudo用户

    1. 编辑 vi /etc/ssh/sshd_config 文件,修改默认端口:默认Port为22,并且已经注释掉了,修改是把注释去掉,并修改成其它的端口. 原来用默认端口:22修改为:8975 (这 ...