问题描述:

I have configured a config.xml file choosing the appropriate properties file depending on environment. I am running this as a Spring Boot app with Apache Camel.

The config looks like this.

<bean id="properties"

class="org.apache.camel.component.properties.PropertiesComponent">

<property name="locations" ref="locations" />

</bean>

<bean id="bridgePropertyPlaceholder"

class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">

<property name="locations" ref="locations" />

<property name="ignoreUnresolvablePlaceholders" value="true" />

</bean>

<beans profile="dev">

<util:list id="locations">

<value>classpath:config/users.properties</value>

<value>classpath:config/application.properties</value>

<value>classpath:config/application-dev.properties</value>

</util:list>

<beans profile="test">

<util:list id="locations">

<value>file:${project.dir}/config/users.properties</value>

<value>file:${project.dir}/config/application.properties</value>

</util:list>

When using the test profile I want to use the external files defined in the config (because I dont want to commit username/password to repo). That seems to work okay.

However, my users.properties file contains:

username=myusername

password=mypassword

and my application.properties contains:

loginParameters=username=${username}&password=${password}

when running java -jar myjar.jar --spring.profiles.active=test I encounter:

java.lang.IllegalArgumentException: Could not resolve placeholder 'username' in string value '${username}&password=${password}'

It clearly loads the properties files because it states:

Loading properties file from URL: file:...../users.properties

Loading properties file from URL: file:...../application.properties

Bridging Camel and Spring property placeholder configurer with id: bridgePropertyPlaceholder

...

And then the exception occurs. How can I resolve the issue where the application.properties file doesn't recognize my properties defined in users.properties? Everything works okay when running the dev-profile.

网友答案:

in your application properties, use $simple{username} and $simple{password} to tell Camel to put the values there.

相关阅读:
Top