`
hekuilove
  • 浏览: 158194 次
  • 性别: Icon_minigender_1
  • 来自: 魔都
社区版块
存档分类
最新评论

重写PropertyPlaceholderConfigurer

阅读更多

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);
	}
}

分享到:
评论

相关推荐

    Spring属性占位符PropertyPlaceholderConfigurer的使用

    在Spring框架中,属性占位符`PropertyPlaceholderConfigurer`是一个重要的工具,用于处理配置文件中的属性值引用。它使得我们可以在XML配置文件中使用占位符`${...}`来引用外部属性文件中的值,从而使应用配置更加...

    Spring中PropertyPlaceholderConfigurer的使用

    Spring 中 PropertyPlaceholderConfigurer 的使用 PropertyPlaceholderConfigurer 是 Spring 框架中的一个重要组件,用于加载和管理 Properties 文件。它能够将 Properties 文件中的键值对注入到 Spring 的 bean 中...

    Spring用代码来读取properties文件实例解析

    Spring读取Properties文件实例...我们可以使用@Value注解、PropertyPlaceholderConfigurer和重写PropertyPlaceholderConfigurer来读取Properties文件中的值。同时,我们也可以使用多个Properties文件来读取配置信息。

    Spring PropertyPlaceholderConfigurer配置文件加载器集成ZooKeeper来实现远程配置读取

    在Spring中,`PropertyPlaceholderConfigurer`是一个非常重要的类,它用于处理属性文件中的占位符,将它们替换为实际的值。这在配置管理中起到了关键作用,特别是在大型分布式系统中,动态配置管理变得尤为重要。...

    Spring如何使用PropertyPlaceholderConfigurer读取文件

    Spring如何使用PropertyPlaceholderConfigurer读取文件 Spring框架中,PropertyPlaceholderConfigurer是一个非常重要的组件,它可以帮助我们读取配置文件,实现系统的配置信息统一管理。在大型项目中,我们往往会将...

    org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

    `org.springframework.beans.factory.config.PropertyPlaceholderConfigurer` 是Spring框架中的一个重要组件,主要负责处理配置文件中的占位符替换。这个类是Spring在初始化bean时用来解析和注入环境变量或系统属性...

    SPRING:bean配置properties

    在Spring框架中,Bean的配置与管理是其核心功能之一,而通过`PropertyPlaceholderConfigurer`进行属性占位符的配置则是实现动态配置的关键技术。本文将深入解析如何利用`PropertyPlaceholderConfigurer`进行bean配置...

    关于spring系统中多系统的配置

    在Spring框架中,`PropertyPlaceholderConfigurer`是一种特殊的Bean,它被用来处理Spring配置文件中的占位符(placeholder),并将它们替换为具体的值。这些值通常来自外部的属性文件,如`.properties`或`.xml`等。...

    spring 启动时加载不同的文件

    - **实现方式**: 通过扩展`PropertyPlaceholderConfigurer`并重写其方法,根据特定条件选择加载不同的配置文件。 #### 三、案例分析与实现 **1. 配置文件设计** - **deploy.properties**: 这个文件包含了一个名为`...

    基于Spring2.0 Property Placeholder配置的源码例子

    Spring 2.0引入了`PropertyPlaceholderConfigurer`类,它是一个Bean工厂后处理器,负责在Bean定义中替换以`${...}`形式的占位符为实际的属性值。这些属性通常来自一个或多个`.properties`文件,可以是classpath下的...

    SSM 读取properties文件

    在Spring框架中,读取properties文件主要通过两种方式:`PropertyPlaceholderConfigurer` 和 `@Value` 注解。 1. **PropertyPlaceholderConfigurer**: 这是一个Spring的bean定义类,它允许我们从properties文件中...

    java 获取properties的几种方式(csdn)————程序.pdf

    Spring提供了`PropertyPlaceholderConfigurer`类,它可以将Properties文件中的值注入到Bean的属性中。在XML配置文件中,我们创建一个`PropertyPlaceholderConfigurer`的Bean,并指定`location`属性为Properties文件...

    Spring 容器后处理器

    `PropertyPlaceholderConfigurer`是一个常用的容器后处理器,它的主要作用是从外部的属性文件中读取配置信息,并将这些配置信息插入到BeanFactory的定义中。这使得可以在不修改主配置文件的情况下更改某些配置值,如...

    说说在Spring中如何引用外部属性文件的方法

    除了使用 PropertyPlaceholderConfigurer 之外,我们还可以使用 context 命名空间来定义属性文件,相对于 PropertyPlaceholderConfigurer 的配置方式,这种方式更优雅。 ``` file-encoding="utf-8"/&gt; ``` 在 ...

    JDBC Template源码.7z

    本文将深入探讨JDBC Template的源码,结合MySQL数据库,展示其在实际应用中的使用,并提及Spring框架中的`PropertyPlaceholderConfigurer`和`BeanPropertyRowMapper`组件。 首先,JDBC Template通过预编译SQL语句、...

    spring配置文件

    `PropertyPlaceholderConfigurer`是Spring提供的一个实用工具类,它允许我们在配置文件中使用占位符 `${...}` 来引用外部属性文件中的值。在示例中,`location`属性指定了属性文件的位置,如`classpath:/spring/...

    spring4.0引用properties

    `PropertyPlaceholderConfigurer`是Spring早期版本中用于注入properties文件中值的bean,而`@ConfigurationProperties`是Spring Boot引入的,更适合现代Spring应用。 使用`PropertyPlaceholderConfigurer`的例子...

    SpringValue注解

    在上面的配置中,我们定义了一个名为 appProperty 的 Bean,该 Bean 使用 PropertyPlaceholderConfigurer 类来加载名为 config.properties 的 properties 文件。 使用 @Value 注解 在 Bean 中,可以使用 @Value ...

    属性占位符配置器

    2. **配置PropertyPlaceholderConfigurer**:在Spring配置文件中,通过`&lt;bean&gt;`元素定义一个`PropertyPlaceholderConfigurer`实例,并设置其`location`属性指向外部属性文件的位置。 3. **使用占位符**:在其他Bean...

    在Spring中使用加密外部属性文件

    Spring默认的`PropertyPlaceholderConfigurer`不直接支持加密的属性文件,但它提供了扩展点,允许我们自定义实现来处理加密后的属性。以下是一种实现方式: 1. 创建一个自定义的`PropertyPlaceholderConfigurer`...

Global site tag (gtag.js) - Google Analytics