tx-annotation.xml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
  5. 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">
  6. <!--扫描组件-->
  7. <context:component-scan base-package="com.cdxw.spring"></context:component-scan>
  8. <!--引入外部属性文件jdbc.properties-->
  9. <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
  10. <!--配置数据源-->
  11. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  12. <property name="driverClassName" value="${jdbc.driver}"></property>
  13. <property name="url" value="${jdbc.url}"></property>
  14. <property name="username" value="${jdbc.username}"></property>
  15. <property name="password" value="${jdbc.password}"></property>
  16. </bean>
  17. <!--配置JdbcTemplate-->
  18. <bean class="org.springframework.jdbc.core.JdbcTemplate">
  19. <!--装配数据源-->
  20. <property name="dataSource" ref="dataSource"></property>
  21. </bean>
  22. <!--配置事务管理器-->
  23. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  24. <property name="dataSource" ref="dataSource"></property>
  25. </bean>
  26. <!--
  27. 开启事务的注解驱动
  28. 将使用@Transactional注解所标识的方法或类中所有的方法使用事务进行管理
  29. 如果@Transactional加在类上,那么这个类中所有的方法都是连接点
  30. transaction-manager属性设置事务管理器的id
  31. 若事务管理器的bean的id默认为transactionManager,则该属性可以不写
  32. -->
  33. <!--作用:将当前的事务管理器(也就是切面)里的通知作用到连接点上-->
  34. <!--补充:在spring的配置文件中,如果某个属性的值使用的是默认值,那么当前这个值就会变成灰色-->
  35. <tx:annotation-driven transaction-manager="transactionManager" />
  36. </beans>