Use property file's property in spring mvc con

2019-08-08 21:14发布

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 contains a property say: propertyName = propertyValue

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

2条回答
做自己的国王
2楼-- · 2019-08-08 21:51

I guess you need to add

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

to your servlet.xml file.

查看更多
叼着烟拽天下
3楼-- · 2019-08-08 21:58

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>

The property file contains there rows

database.url=localhost:1521:xe
database.username=dbusername
database.password=dbpassword
查看更多
登录 后发表回答