<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:com/starxing/test/database.properties</value>
</property>
<!-- 使用locations属性定义多个配置文件
<property name="locations">
<list>
<value>classpath:config/mail.properties</value>
<value>classpath:config/database.properties</value>
</list>
</property>
-->
</bean>
示例:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url">
<value>${database.url}</value>
</property>
<property name="driverClassName">
<value>${database.driver}</value>
</property>
<property name="username">
<value>${database.user}</value>
</property>
<property name="password">
<value>${database.password}</value>
</property>
</bean>

本文深入探讨了如何使用Spring框架进行数据库配置,包括通过PropertyPlaceholderConfigurer类加载配置文件及如何在DataSource bean中注入数据库连接参数。

被折叠的 条评论
为什么被折叠?



