import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
/**
*
* @author <br>
* @date 2013年8月10日上午11:16:24<br>
*/
public class DabeiPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
public DabeiPropertyPlaceholderConfigurer() {
PROPERTIES = new HashMap<String, String>();
}
/**
* 属性key,value
*/
private static Map<String, String> PROPERTIES;
/**
*
*/
protected void convertProperties(Properties props) {
Set<String> keys = props.stringPropertyNames();
for (String key : keys) {
String value = props.getProperty(key);
PROPERTIES.put(key, value);
}
super.convertProperties(props);
}
/**
*
* @param key
* @return<br>
* @date 2013年8月11日上午1:46:07<br>
* @author <br>
*/
public String getValue(String key) {
return PROPERTIES.get(key);
}
}
分享到:
相关推荐
但是,如果我们需要在代码中直接读取Properties文件中的值,而不使用@Value注解,我们可以重写PropertyPlaceholderConfigurer类来实现。例如: ```java public class PropertyPlaceholder extends ...
- **实现方式**: 通过扩展`PropertyPlaceholderConfigurer`并重写其方法,根据特定条件选择加载不同的配置文件。 #### 三、案例分析与实现 **1. 配置文件设计** - **deploy.properties**: 这个文件包含了一个名为`...
- 通过`EnvironmentAware`接口回调:实现该接口并重写`setEnvironment(Environment)`方法。 - 通过`ApplicationContext`:获取`ApplicationContext`后,调用`getEnvironment()`方法。 7. **依赖查找Environment**...
在Bean的生命周期中,Spring还提供了对Bean的属性进行动态调整的能力,例如通过`PropertyPlaceholderConfigurer`或`@Value`注解来设置Bean的属性值。 在Bean完成其职责后,最终会到达销毁阶段。销毁有两种方式: 1...
该类继承自PropertyPlaceholderConfigurer,重写了processProperties方法,用于加载Apollo配置中心的配置。 ```java import com.alibaba.dubbo.common.utils.ConfigUtils; import ...
在上述代码中,我们定义了一个名为`EncryptPropertyPlaceholderConfigurer`的类,它重写了`convertProperty`方法,用于对特定属性(例如`db.password`)进行解密。解密过程使用了AES算法,并且假设我们已经有了一个...