由Could not resolve placeholder 'xxx.xxx' in string value "${xxx.xxx}引发的项目中配置文件那些事

近日在编写基于SOA的商城项目,项目由父工程及若干子模块构成,在编写过程中,为了相互协作及维护方便,于是将一些连接地址信息抽取出来单独放在配置文件中,并且放到了common公用模块内
环境描述
在dubbo中两个xml文件需要各自引入自己的配置于是分别写了如下引入

<!-- application-dubbo.xml 中 -->  
<context:property-placeholder location="classpath:dubbo.properties" />  
  
<!--application-jedis.xml 中-->  
<context:property-placeholder location="classpath:jedis.properties" />  

于是启动dubbo服务:Main.main(args)。
控制台中报错:
Could not resolve placeholder ‘xxx.xxx’ in string value "${xxx.xxx}
经过调试,证明不是找不到文件,排除properites文件路径错误、拼写错误。
查阅网上资料有如下描述:
一定要记住,不管是在一个Spring文件还是在多个Spring文件被统一load的情况下,直接写:

<context:property-placeholder location="" />  
<context:property-placeholder location="" />   

是不允许的,这样的引入方式会造成冲突。

  1. 解决冲突:
<context:property-placeholder location="classpath:dubbo.properties" ignore-unresolvable="true" />

添加了ignore-unresolvable="true"属性,注意,所有引入的地方都要添加,即使一个添加另一个不添加也不行。

  1. 另外,对于web项目:如果项目中引入了其他jar的配置文件properties,那么可以在web.xml中配置:
<!-- 上下文参数 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<!-- classpath:表示从当前项目加载  classpath*表示从当前项目及依赖的jar中加载,当所依赖的工具类例如redis又想从中加载配置文件时,可以考虑此用法  -->
		<param-value>classpath*:applicationContext-*.xml</param-value>
	</context-param>

总结一下,项目中多个spring文件分别引入各自对应的properties或yml配置,应在引入出添加ignore-unresolvable属性值为true。
web项目需要引入依赖jar中的配置文件,则在web.xml中contextConfigLocation参数设置为classpath*:applicationContext-*.xml,classpath后面的星号很重要。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Could not resolve placeholder 'app.name' in value "${app.name}"是一个报错信息,它表示在Spring配置文件找不到占位符'${app.name}'对应的值。 这可能是因为在属性文件没有定义或配置了错误的占位符。 根据引用和引用的报错信息,可能有两个原因导致这个问题。一个是在属性文件没有定义'info.name'或'app.name'这些属性的值,另一个是在配置文件使用了错误的占位符。 解决这个问题的方法是,首先检查属性文件是否正确定义了占位符对应的属性值。 确保属性文件包含了'info.name'或'app.name'这些属性,并且它们有正确的值。 如果属性文件没有定义这些属性,可以手动添加它们并设置相应的值。 另外,还需要检查配置文件是否使用了正确的占位符。 确保在配置文件使用的占位符与属性文件定义的占位符名称一致。 如果使用了错误的占位符,需要将其更正为正确的占位符名称。 总结起来,解决Could not resolve placeholder 'app.name' in value "${app.name}"的问题,需要确保属性文件定义了正确的占位符对应的属性值,并且配置文件使用了正确的占位符名称。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [nacos config:Could not resolve placeholder ‘info.name‘ in value “${info.name}](https://blog.csdn.net/qq_42224683/article/details/114918992)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [若依报:Could not resolve placeholder ‘shiro.session.expireTime‘ in value “${shiro.session....](https://blog.csdn.net/qq_53127029/article/details/131370538)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [解决Unable to access 'https://gitee.com/自己的项目/': Could not resolve host: gitee.com问题](https://download.csdn.net/download/weixin_38742520/12923630)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hongmin.shm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值