逝者如斯夫

静而思之
数据加载中……

关于 PropertyPlaceholderConfigurer

在Spring中,使用PropertyPlaceholderConfigurer可以在XML配置文件中加入外部属性文件,例如:

    <bean id="propertyConfigurer"
          class
="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        
<property name="location" value="classpath:config/jdoserver.properties"/>
    
</bean>

但是好像在属性文件定义中却不支持多个属性文件的定义,比如不能这样用config/*.properties。

经过查看源码,发现可以使用locations属性定义多个配置文件:
<property name="locations">
            
<list>
                
<value>classpath:config/maxid.properties</value>
                
<value>classpath:config/jdoserver.properties</value>
            
</list>
</property>

使用外部属性后如下:

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        
<property name="driverClassName" value="${jdbc.agent.driver}"/>
        
<property name="url" value="${jdbc.agent.main.url}"/>
    
</bean>

上面的例子是采用Spring DriverManagerDataSource包装VJDBC Connection的用法,没有提供连接池功能,只能作作简单的单机连接。

posted on 2007-11-27 18:19 ideame 阅读(1100) 评论(0)  编辑  收藏 所属分类: Spring


只有注册用户登录后才能发表评论。


网站导航: