在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的用法,沒有提供連接池功能,只能作作簡單的單機連接。