`
ly_mad
  • 浏览: 29521 次
社区版块
存档分类
最新评论

context:property-placeholder读取单一文件问题

 
阅读更多

在多个Spring配置文件中使用 <context:property-placeholder location="conf/A.properties"/> 单独读取文件时,会出现只有一个文件被读取,原因是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配置文件不再读取配置文件:

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

 

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

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics