【问题标题】:In Spring, getting "java.lang.IllegalArgumentException: Could not resolve placeholder" despite having defined "PropertyPlaceholderConfigurer"在 Spring 中,尽管定义了“PropertyPlaceholderConfigurer”,但得到“java.lang.IllegalArgumentException:无法解析占位符”
【发布时间】:2016-09-24 23:58:04
【问题描述】:

我正在使用 Spring 3.2.11.RELEASE 和 Maven 3.3。我在我的应用程序上下文文件中定义了这个……

<bean id="localPropertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="locations">
        <list>
            <value>classpath:quickbase.properties</value>
        </list>
        </property>
</bean> 
…
<bean id=“myClient" class="org.mainco.subco.mysystem.MyClient">
    <constructor-arg index="0" type="String" value="${quickbase.username}" />
    <constructor-arg index="1" type="String" value="${quickbase.password}" />
    <constructor-arg index="2" type="String" value="${quickbase.url}" />
</bean>

但是当我运行测试时,出现以下错误

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myClient' defined in class path resource [META-INF/spring/applicationContext-orders.xml]: Could not resolve placeholder 'quickbase.username' in string value "${quickbase.username}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'quickbase.username' in string value "${quickbase.username}"

这让我很困惑,因为在我的目标/类目录中,我可以看到一个文件“quickbase.properties”,其中定义了“quickbase.username”。我不知道我还需要检查什么。

【问题讨论】:

    标签: spring properties applicationcontext property-placeholder


    【解决方案1】:

    我今天收到了类似的错误。我通过在美元和第一个大括号 { 之间添加一点空格来解决它。我相信 java 运行时正试图解决一个意外的占位符。以下是示例:

    <bean id=“myClient" class="org.mainco.subco.mysystem.MyClient">
        <constructor-arg index="0" type="String" value="$ {quickbase.username}" />
        <constructor-arg index="1" type="String" value="$ {quickbase.password}" />
        <constructor-arg index="2" type="String" value="$ {quickbase.url}" />
    </bean>
    

    【讨论】:

    • 我更改了代码 - 从 @Value("${connstring}") 到 @Value("$ {connstring}") - 这太疯狂了......
    • 很高兴我能帮上忙 :)
    【解决方案2】:

    您的应用程序中有多个org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 可能是造成这种情况的原因。

    看看这个:Could not resolve Spring property placeholder

    可能是您正在寻找的答案..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2016-07-24
      • 2018-02-20
      • 2017-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多