spring 加载多个常量配置文件的问题??

今天新建了一个shiro.properties配置文件,将文件引入到shiro.xml 配置文件中为了替换文件中的占位符信息。结果出现了下面的异常信息:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'simpleCookie' defined in class path resource [spring-shiro.xml]: Could not resolve placeholder 'shiro.cookie.path' in value "${shiro.cookie.path}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'shiro.cookie.path' in value "${shiro.cookie.path}"
	at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:223)
	at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:180)
	at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:152)

主要原因通过context:property-placeholder 默认情况下ignore-unresolvable 属性是fasle,在执行doProcessProperties方法时进行占位符替换的时候,发现找不到替换占位符的信息则会抛出异常信息。

解决方法:

  • 通过<context:property-placeholder ignore-unresolvable=“true” order=“1”> 中 ignore-unresolvable属性设置true

表示当前PropertySourcesPlaceholderConfigurer实例在找不到对应的占位符的情况会将占位符保存下来,然后通过下一个PropertySourcesPlaceholderConfigurer实例去解决这个问题,如果还是找不到则抛出异常。

  • <context:property-placeholder > location 属性中设置多个配置文件,以逗号分隔:
<context:property-placeholder location="classpath*:shiro.properties,classpath*:resources.properties" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值