导入所需jar包
spring-tx-4.3.9.RELEASE
ojdbc.jar
commons-dbcp.jar 连接池使用到数据源
commons-pool.jar 连接池
spring-jdbc-4.3.9.RELEASE.jar
aopalliance.jar
在配置文件中配置
1增加事务tx的命名空间
xmlns:tx="http://www.springframework.org/schema/tx"
2增加对事务的支持
<tx:annotation-driven transaction-manager="txManager" />
3配置事务管理器
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
4配置数据源
<bean id ="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="xxx"></property>
<property name="url" value="xxx"></property>
<property name="username" value="xxx"></property>
<property name="password" value="xxx"></property>
<property name="maxActive" value="xxx"></property>
<property name="maxIdle" value="xxx"></property>
</bean>
5将需要 成为事务的方法 前增加注解:
@Transactional(readOnly=false,propagation=Propagation.REQUIRED)