tx-xml.xml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. xmlns:aop="http://www.springframework.org/schema/aop"
  6. 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 http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
  7. <!--扫描组件-->
  8. <context:component-scan base-package="com.cdxw.spring"></context:component-scan>
  9. <!--引入外部属性文件jdbc.properties-->
  10. <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
  11. <!--配置数据源-->
  12. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  13. <property name="driverClassName" value="${jdbc.driver}"></property>
  14. <property name="url" value="${jdbc.url}"></property>
  15. <property name="username" value="${jdbc.username}"></property>
  16. <property name="password" value="${jdbc.password}"></property>
  17. </bean>
  18. <!--配置JdbcTemplate-->
  19. <bean class="org.springframework.jdbc.core.JdbcTemplate">
  20. <!--装配数据源-->
  21. <property name="dataSource" ref="dataSource"></property>
  22. </bean>
  23. <!--配置事务管理器-->
  24. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  25. <property name="dataSource" ref="dataSource"></property>
  26. </bean>
  27. <!--配置事务通知-->
  28. <tx:advice id="tx" transaction-manager="transactionManager">
  29. <tx:attributes>
  30. <tx:method name="buyBook"/>
  31. <tx:method name="*"/>
  32. </tx:attributes>
  33. </tx:advice>
  34. <aop:config>
  35. <aop:advisor advice-ref="tx" pointcut="execution(* com.cdxw.spring.service.impl.*.*(..))"></aop:advisor>
  36. </aop:config>
  37. </beans>