一、通过context:property-placeholder加载配置文件jdbc.properties中的内容
ignore-unresolvable="true"/>
上面的配置和下面配置等价,是对下面配置的简化:
classpath:jdbc.properties
二、使用util:properties标签进行暴露properties文件中的内容
注意:使用上面这行配置,需要在spring-dao.xml文件的头部声明以下部分:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
三、通过PropertyPlaceholderConfigurer在加载上下文的时候暴露properties到自定义子类的属性中以供程序中使用
classpath:jdbc.properties
自定义类PropertyConfigurer的声明如下:
/**
* Desc:properties配置文件读取类
*/
public class PropertyConfigurer extends PropertyPlaceholderConfigurer {
private Properties props; // 存取properties配置文件key-value结果
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
throws BeansException {