1

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 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

How can I use this to call props.properties inside src/main/resources to do file I/O in Spring?
0

I guess you need to add

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

to your servlet.xml file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.