---
title: "context:property-placeholder读取单一文件问题"
author: "ly_mad"
date: "2014-01-08T15:38:58Z"
tags: []
slug: "context-property-placeholder"
draft: false
lastmod: "2014-01-08T15:38:58Z"
id: 2001337
url: "https://ly-mad.iteye.com/blog/2001337"
---

在多个Spring配置文件中使用 &lt;context:property-placeholder location="conf/A.properties"/&gt; 单独读取文件时，会出现只有一个文件被读取，原因是placeholder只会实例化一次；

系统报错如下：

Invalid bean definition with name “dataSource”; defined in ServletContext resource \[/WEB-INF/applicationContext.xml]: Could not resolve placeholder ${jdbc.driverClass};   

解决办法有两种：

1、在单独的spring.xml使用\*匹配placeholder读取文件，其余各spring.xml配置文件不再读取配置文件：

 &lt;context:property-placeholder location="classpath\*:conf/\*.properties"/&gt;

 

 2、在单独的spring.xml使用如下配置方式，其他各spring.xml配置文件不再读取配置文件：

&lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;  
        &lt;property name="locations"&gt;  
            &lt;list&gt;  
                &lt;value&gt;classpath:jdbc.properties&lt;/value&gt;  
                &lt;value&gt;classpath:memcached.properties&lt;/value&gt;  
            &lt;/list&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;