spring报“Could not resolve placeholder”错误

 

spring报“Could not resolve placeholder”错误

标签: springbeanxmlurl
  19487人阅读  评论(7)  收藏  举报
  分类:
 

org.springframework.beans.factory.BeanDefinitionStoreException


Invalid bean definition with name '******' defined in null: Could not resolve placeholder 'displayName'


我未深究原因,猜测原因如下:


有可能是因为你配置了多个 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer


这个配置用于 xml 中的占位符,如下:

<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />


假设 a.xml 配置了一个 PropertyPlaceholderConfigurer ,并且成功了。


后来,b.xml 也配置了一个 PropertyPlaceholderConfigurer ,这时候如果不做特别配置,b.xml 里配置的placeholder将无法使用,并报上面的错误。

************************************************************************************************************

解决方法:a.xml中配置第一个 PropertyPlaceholderConfigurer 时,将ignoreUnresolvablePlaceholders的值设为true


如下所示:

<bean id="myConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>


这个配置告诉spring,当某个placeholder无法找到时,先不要报错,并尝试用另一个PropertyPlaceholderConfigurer来设置placeholder的值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]和\[2\]中的错误信息显示,出现了"Could not resolve placeholder"的错误,这意味着在配置文件中找不到对应的占位符。具体来说,错误信息中提到了'spring.datasource.druid.initialSize'和'show.tips.text'这两个占位符无法解析。引用\[3\]中给出了一些解决方法。首先,确认配置文件中是否存在这些字段,并且字段名是否正确。其次,检查配置文件是否正确引用了相应的配置文件。在Spring Boot中,我们可以使用application.yml文件来指定使用哪个配置文件。例如,可以在application.yml中使用'spring.profiles.active'来指定使用名为'druid'的配置文件。如果以上步骤都正确无误,但仍然出现该错误,可能是由于其他原因导致的。可以进一步检查项目的依赖和版本是否正确,以及相关的配置是否正确。 #### 引用[.reference_title] - *1* *3* [springboot启动错Could not resolve placeholder xxx](https://blog.csdn.net/a_helloword/article/details/118334203)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [【解决方法汇总】SpringBoot项目错 Could not resolve placeholder ‘‘ in value “${}“](https://blog.csdn.net/yu1812531/article/details/123466616)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值