1

環境に応じて適切なプロパティ ファイルを選択する config.xml ファイルを構成しました。これを Apache Camel を使用して Spring Boot アプリとして実行しています。

構成はこんな感じ。

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

テストプロファイルを使用する場合、構成で定義された外部ファイルを使用したい (ユーザー名/パスワードをリポジトリにコミットしたくないため)。それはうまくいくようです。

ただし、users.properties ファイルには以下が含まれています。

username=myusername
password=mypassword

そして私のapplication.propertiesには以下が含まれています:

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

実行java -jar myjar.jar --spring.profiles.active=test中に遭遇する:

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

次のように記載されているため、プロパティファイルを明確にロードします。

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
...

そして、例外が発生します。application.properties ファイルが users.properties で定義されたプロパティを認識しないという問題を解決するにはどうすればよいですか? dev-profile を実行すると、すべて正常に動作します。

4

1 に答える 1

0

アプリケーションのプロパティで、 $simple{username} と $simple{password} を使用して Camel に値を設定するように指示します。

于 2016-08-12T06:47:30.217 に答える