- Spring使用配置文件读取jdbc.properties
-
在beans.xml中加入两个必须的bean
[html]
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/jdbc.properties" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>在web-inf下面的jdbc.properties
[html]
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://210.30.12.3:3306/spring
jdbc.username=root
jdbc.password=sa