关于spring配置文件<context:property-placeholder>

首先,Spring容器会加载多个<context:property-placeholder location=""/>,但是取值的时候只会在第一个<context:property-placeholder location=""/>加载的文件中去寻找key名字。

所以,在配置context:property-placeholder 时,应在一个中配置,多个文件使用逗号分割开;例如:<context:property-placeholder location="classpath:config.properties,classpath:ipParameters.properties"/>

正确配置:<context:property-placeholder location="classpath:config.properties,classpath:ipParameters.properties"/>

错误配置:<context:property-placeholder location="classpath:config.properties"/>

                  <context:property-placeholder location="classpath:ipParameters.properties"/>

错误提示:

 23:32:03,115 [RMI TCP Connection(3)-127.0.0.1] INFO  [org.springframework.context.support.PropertySourcesPlaceholderConfigurer] - Loading properties file from class path resource [config.properties]
2017-08-08 23:32:03,134 [RMI TCP Connection(3)-127.0.0.1] INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@64bbe1ee: defining beans [org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,org.springframework.context.support.PropertySourcesPlaceholderConfigurer#1,HBAdContentService,HBAdminService,HBCategoryService,
2017-08-08 23:32:03,135 [RMI TCP Connection(3)-127.0.0.1] ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'ipParamters' defined in class path resource [spring.xml]: Could not resolve placeholder 'tableUrl' in string value "${tableUrl}" 

猜你喜欢

转载自blog.csdn.net/KingJin_CSDN_/article/details/77094967
今日推荐