Spring中报"Could not resolve placeholder"的解决方案
2018-03-08 15:09
405 查看
除去properites文件路径错误、拼写错误外,出现”Could not resolve placeholder”很有可能是使用了多个PropertyPlaceholderConfigurer或者多个
因为spring扫描注册PropertyPlaceholderConfigurer的bean被设置为单例模式,spring只会扫描一个PropertyPlaceholderConfigurer或者
参照:http://stamen.iteye.com/blog/1926166
<context:property-placeholder>(
<context:property-placeholder>底层也是PropertyPlaceholderConfigurer)的原因。
因为spring扫描注册PropertyPlaceholderConfigurer的bean被设置为单例模式,spring只会扫描一个PropertyPlaceholderConfigurer或者
<context:property-placeholder>配置,其它多余将被忽略,所以才会出现替代属性值的占位符无法解析。
解决方案:
方案一:
坚持使用多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>,那么需要添加ignoreUnresolvablePlaceholders属性或者ignore-unresolvable属性,设置其值为true如下代码所示:
<bean id="xxx" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="xxx.properties" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> </bean> <bean id="yyy" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="yyy.properties" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> </bean>或者:
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/> <context:property-placeholder location="yyy.properties" ignore-unresolvable="true"/>参照:http://blog.csdn.net/linwei_1029/article/details/6873764
方案二:
将多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>合并到一个里面,统一加载所有的资源文件如下代码所示:
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:xxx.properties</value> <value>classpath:jyyy.properties</value> </list> </property> </bean>或者:
<context:property-placeholder location="classpath:xxx.properties,classpath:yyy.properties"/>加载的日志可以发现,创建的propertyPlaceholderConfigurer这个bean是一个单例bean
参照:http://stamen.iteye.com/blog/1926166
相关文章推荐
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- spring cloud config---Could not resolve placeholder 'foo' in string value "${foo}"
- Could not resolve placeholder 'spring.security.mapping.directory' in string value "${spring.security
- "Could not resolve placeholder"解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Could not resolve placeholder"的解决方案
- 启动错误:Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
- "Could not resolve placeholder"解决方案
- Could not resolve placeholder 'master.jdbc.url' in string value "${master.jdbc.url}"
- "Could not resolve placeholder"解决方案
- Could not resolve placeholder 'redis.pool.maxTotal' in string value "${redis.pool.maxTotal}
- spring报“Could not resolve placeholder”错误,解决方案
- vs .net 2005 打开VSS项目时出现:"could not find the visual sourcesafe internet web service connection"的解决方案
- 错误笔记之Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"