PropertyPlaceholderConfigurer扩展---spring读取properties配置文件
2016-05-09 12:02
507 查看
spring读取properties配置文件 这样方便于在spring的xml配置中直接用表达式来表示一些不变的变量
如上配置 其中ServletContextPropertyPlaceholderConfigurer是集成了PropertyPlaceholderConfigurer的 下面的配置是一些properties的文件 放在class根目录下 这样在spring的xml配置文件中中就能通过标签使用properties中的配置项了
比如配置数据库就可以使用了
<!-- 数据源定义 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<bean
class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="searchContextAttributes" value="true" />
<property name="contextOverride" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:test.properties</value>
<value>classpath:test1.properties</value>
</list>
</property>
</bean>
如上配置 其中ServletContextPropertyPlaceholderConfigurer是集成了PropertyPlaceholderConfigurer的 下面的配置是一些properties的文件 放在class根目录下 这样在spring的xml配置文件中中就能通过标签使用properties中的配置项了
比如配置数据库就可以使用了
<!-- 数据源定义 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="${jdbc.initialSize}" />
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxActive" value="${jdbc.maxActive}" />
<property name="maxWait" value="${jdbc.maxWait}" />
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<property name="logAbandoned" value="${jdbc.logAbandoned}" />
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
</bean>
相关文章推荐
- Spring中配置和读取多个Properties文件-- PropertyPlaceholderConfigurer
- Spring —— web.xml 中用 PropertyPlaceholderConfigurer 类读取properties 文件 或 属性
- spring管理属性配置文件properties——PropertiesFactoryBean和PropertyPlaceholderConfigurer的区别
- spring管理属性配置文件properties——使用PropertyPlaceholderConfigurer
- PropertyPlaceholderConfigurer的用法(使用spring提供的类读取数据库配置信息.properties)
- 【转】spring管理属性配置文件properties——使用PropertiesFactoryBean|spring管理属性配置文件properties——使用PropertyPlaceholderConfigurer
- spring中的PropertyPlaceholderConfigurer访问properties文件配置
- spring通过.PropertyPlaceholderConfigurer读取配置文件
- Spring代码实例系列-09:通过Spring PropertyPlaceholderConfigurer将properties配置的属性注入到xml配置文件中
- Spring PropertyPlaceholderConfigurer初始化properties配置文件
- Spring PropertyPlaceholderConfigurer读取本地路径文件
- Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />
- Spring中扩展 PropertyPlaceholderConfigurer处理加密属性文件
- Spring PropertyPlaceholderConfigurer Usage - 使用系统变量替换spring配置文件中的变量
- Spring环境搭建之:通过PropertyPlaceholderConfigurer加载属性配置文件:
- spring中 context:property-placeholder 导入多个独立的 .properties配置文件
- Spring PropertyPlaceholderConfigurer Usage - 使用系统变量替换spring配置文件中的变量
- Spring PropertyPlaceholderConfigurer解析Java Properties属性文件值
- PropertyPlaceholderConfigurer读取配置文件
- 使用PropertyPlaceholderConfigurer读取配置文件