<!-- 启动@AspectJ框架的支持 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<context:component-scan base-package="com.lovo">
<context:excluede-filter type="" expression=""></context:excluede-filter>
</context:component-scan>
<!-- 配置数据源DataSource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerData">
<!-- &在配置文件中代表& -->
<property name="url" value="jdbc:mysql:///test0323?characterEncoding=utf-8"></property>
<property name="username" value="root"></property>
<property name="password" password="12345"></property>
</bean>
<!-- 配置Session工厂 -->
<bean id="sessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 加载mybatis.cfg.xml文件 -->
<property name="configLocation" value="classpath:mybatis.cfg.xml"></property>
</bean>
<!-- 将Mapper配置文件和Session进行关联 -->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.lovo.mapper"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean"></property>
</bean>
<!-- 配置事务管理 -->
<bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 事务管理方式一,适合于单数据库,使用注解的方式来管理事务
<tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>-->
<!-- 事务管理方式二,采用springAOP来声明式地处理事务,声明式就是脱离java代码,通常是声明在配置中 -->
<!-- 声明一个通知 -->
<tx:advice id="txAdvice" transaction-manager="dataSourceTransactionManager">
<tx:attributes>
<!-- name方法名,propagation事务类型 -->
<tx:method name="*" propagation="SUPPORTS" read-only="true"></tx:method>
<!-- rollback-for出现异常时回滚 -->
<tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"></tx:method>
</tx:attributes>
</tx:advice>
<!-- 配置AOP事务关联 -->
<aop:config>
<!-- 定义一个切点 -->
<aop:pointcut expression="execution(* com.lovo.service.*ServiceImpl.*(..)" id="serviceMethod"/>
<!-- 将通知和切点关联起来 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
</aop:config>