Dmitry Senkovich
Dmitry Senkovich

Reputation: 5911

Spring can't resolve command line arguments

I'm migrating a pretty legacy application to Spring Boot. It is configured with xml and I've got the following snippet there:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="localOverride" value="true"/>
    <property name="locations">
        <list>
            <value>classpath:conf/${ENV}/some.properties</value>
        </list>
    </property>
</bean>

I'm starting the app with the following command line:

mvn spring-boot:run -Dserver.port=22222 -DENV=int

But it fails on startup with the following message:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'ENV' in value "classpath:conf/${ENV}/some.properties"

It worked before and now I've got spring-boot-starter-web.

Any suggestions? Thank you in advance!

UPDATE: It doesn't work in @PropertySource, not in xml, sorry for misunderstanding

Upvotes: 0

Views: 1433

Answers (2)

Mehraj Malik
Mehraj Malik

Reputation: 15854

You should use #systemEnvironment['propertyName'] or

#{systemProperties['propertyName']}

 <value>classpath:conf/#{systemEnvironment['ENV']/some.properties</value>

Because

${propertyName} 

You can only access properties defined in .properties file

Upvotes: 0

pvpkiran
pvpkiran

Reputation: 27038

When running the application using maven spring boot plugin(like you are doing) you need to specify like this

mvn spring-boot:run -Drun.arguments="--server.port=22222, --ENV=int"

If you want to run your application using java -jar command. This is the way

java -jar -Dserver.port=22222 -DENV=int XYZ.jar

Upvotes: 2

Related Questions