以下是一些常用配置:
<?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:context="http://www.springframework.org/schema/context" 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/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--扫描service层包-->
<context:component-scan base-package="com.atguigu.service"/>
<!--事务管理器-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--
事务注解驱动
proxy-target-class属性值决定是基于接口的还是基于类的代理被创建
proxy-target-class="true" :基于JDK动态代理(有接口)
proxy-target-class="true" :基于CGLIB类代理(没有接口)
-->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
</beans>