Spring集成JDBC配置文件
阿新 • • 發佈:2018-06-07
drive zhang 4.3 classname apach not nag xmlns idle
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test?serverTimezone=GMT" /> <propertyname="username" value="root" /> <property name="password" value="zhangpn" /> <property name="initialSize" value="1" /> <property name="maxTotal" value="20" /> <property name="maxIdle" value="2" /> <property name="minIdle" value="1" /></bean> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <tx:annotation-driven transaction-manager="txManager"/> </beans>
dbcp創建一個數據源
創建一個DataSourceTransactionManager數據源事務管理員
聲明使用註解方式使用數據源事務管理員
在Service中加上@Transaction註解,OK。
Spring集成JDBC配置文件