ITeye博客

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

ly_mad · 2014-01-08 15:38 · Java服务器 · Markdown

在多个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>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。