在spring mvc配置servlet xml中使用属性文件的属性 [英] Use property file's property in spring mvc configuration servlet xml

查看:38
本文介绍了在spring mvc配置servlet xml中使用属性文件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码行读取 spring mvc 配置 servlet xml 文件中的 config.properties 文件.

I use following line of code to read config.properties file in my spring mvc configuration servlet xml file.

<context:property-placeholder location="file:///${config.properties}" />

config.properties 包含一个属性说:propertyName = propertyValue

我想在 spring mvc 配置 servlet xml 文件中使用这个 propertyName 的值.

I want to use this propertyName's value in spring mvc configuration servlet xml file.

推荐答案

以下是使用从属性文件中获取的属性配置为池的示例

Here is an example of configuring as pool with properties taken from a properties file

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@${database.url}" />
    <property name="username" value="${database.username}" />
    <property name="password" value="${database.password}" />
    <property name="validationQuery" value="SELECT 1 FROM DUAL" />
    <property name="testWhileIdle" value="true" />
    <property name="timeBetweenEvictionRunsMillis" value="300000" />
    <property name="numTestsPerEvictionRun" value="6" />
    <property name="minEvictableIdleTimeMillis" value="1800000" />
    <property name="initialSize" value="3" />
    <property name="maxActive" value="75" />
    <property name="maxIdle" value="75" />
    <property name="maxWait" value="5000" />
    <property name="poolPreparedStatements" value="true" />
    <property name="maxOpenPreparedStatements" value="100" />
</bean>

属性文件包含行

database.url=localhost:1521:xe
database.username=dbusername
database.password=dbpassword

这篇关于在spring mvc配置servlet xml中使用属性文件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆