由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
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hongmin.shm

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

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

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

打赏作者

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

抵扣说明:

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

余额充值