spring jdbc.property的配置与使用

jdbc.properties

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/ssi1
username=root
password=root

 在 applicationContext.xml 中增加如下代码

<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties </value>
			</list>
		</property>
	</bean>
   	
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName">
			<value>${driver}</value>
		</property>
		<property name="url">
			<value>${url}</value>
		</property>
		<property name="username">
			<value>${username}</value>
		</property>
		<property name="password">
			<value>${password}</value>
		</property>
	</bean>

 注意:jdbc.properties文件放在src下

原文地址:https://www.cnblogs.com/liuyq/p/3687280.html