user253202
user253202

Reputation:

spring configuration with system property

I have a question. Currently i start jboss with -P property that links to file with properties. In this property file i have property - mongo.server.list=127.0.0.1. In Spring configuration i try to set this property as value of constructor of bean. But spring treat ${mongo.server.list} as value itself.

Here is the code

<bean id="systemPropertyConfigurer"
   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
</bean>

<bean id="mongo" class="com.mongodb.Mongo">
    <constructor-arg index="0">
        <value>${mongo.server.list}</value>
    </constructor-arg>
</bean>

Upvotes: 1

Views: 2502

Answers (3)

Muhammad Imran Tariq
Muhammad Imran Tariq

Reputation: 23352

You should set your property file as a JVM property and read it in spring mvc configuration file as:

<context:property-placeholder location="file:///${-P}" />

Upvotes: 2

Romain Linsolas
Romain Linsolas

Reputation: 81607

Did you try to start your server using -Dmongo.server.list=127.0.0.1 ? (i.e. using -D instead of -P, and no space between -D and the property name)

Upvotes: 1

Aravind Yarram
Aravind Yarram

Reputation: 80176

You should specify the property as a JVM arg as -Dmongo.server.list=....

Upvotes: 1

Related Questions