spring 数据库mysql的配置注入方式

<bean id="accountDao" class="org.itcruce.dao.impl.AccountDaoImpl">
		<property name="runner" ref="runner"></property>
	</bean>

	<!-- 注入数据源 -->
	<bean id="runner" class="org.apache.commons.dbutils.QueryRunner"
		scope="prototype">
		<constructor-arg name="ds" ref="dataSource"></constructor-arg>
	</bean>

	<!-- 配置数据源 -->
	<bean id="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<!--连接数据库的必备信息 -->
		<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
		<property name="jdbcUrl"
			value="jdbc:mysql://localhost:3306/itcruce?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC"></property>
		<property name="user" value="root"></property>
		<property name="password" value="Password1"></property>
	</bean>

  

posted @ 2020-02-25 12:39  MakeCoder  阅读(622)  评论(0编辑  收藏  举报