【问题标题】:Could not resolve placeholder in string value with external files无法使用外部文件解析字符串值中的占位符
【发布时间】:2015-11-06 12:16:42
【问题描述】:

我已经配置了一个 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>

使用测试配置文件时,我想使用配置中定义的外部文件(因为我不想将用户名/密码提交给 repo)。这似乎工作正常。

但是,我的 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 时一切正常。

【问题讨论】:

    标签: spring spring-boot apache-camel spring-properties


    【解决方案1】:

    在您的应用程序属性中,使用 $simple{username} 和 $simple{password} 告诉 Camel 将值放在那里。

    【讨论】:

      猜你喜欢
      • 2017-07-23
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 2018-06-17
      • 1970-01-01
      相关资源
      最近更新 更多