Spring配置文件applicationContext.xml(3)开启事务和注解

  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <beans   
  3. xmlns="http://www.springframework.org/schema/beans"  
  4. xmlns  si="http://www.w3.org/2001/XMLSchema-instance"  
  5. xmlns:context="http://www.springframework.org/schema/context"  
  6. xmlns:aop="http://www.springframework.org/schema/aop"  
  7. xmlns:tx="http://www.springframework.org/schema/tx"  
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans   
  9. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
  10. http://www.springframework.org/schema/context   
  11. http://www.springframework.org/schema/context/spring-context-2.5.xsd   
  12. http://www.springframework.org/schema/aop   
  13. http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
  14. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   
  15. ">   
  16.   
  17. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>   
  18.   
  19. <!-- 配置数据源 -->   
  20. <bean id="dataSource" destroy-method="close">   
  21. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>   
  22. <property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8"/>   
  23. <property name="username" value="root"/>   
  24. <property name="password" value=""/>   
  25. <!-- 链接池启动时的初始值 -->   
  26. <property name="initialSize" value="1"/>   
  27. <!-- 链接池的最大值 -->   
  28. <property name="maxActive" value="500"/>   
  29. <!-- 最大空闲值.当通过一个高峰时间后,链接池能够慢慢将已经用不到的链接慢慢释放一部分,一直减小到maxIdle为止 -->   
  30. <property name="maxIdle" value="2"/>   
  31. <!--  最小空闲值.当空闲的链接数少于阀值时,链接池就会预申请去一些链接,以避免洪峰来时来不及申请 -->   
  32. <property name="minIdle" value="1"/>   
  33. </bean>   
  34.   
  35. <!-- 配置事务管理器-->   
  36. <bean id="txManager">   
  37. <property name="dataSource" ref="dataSource"/>   
  38. </bean>   
  39. <!-- 配置业务bean -->   
  40. <bean id="personService">   
  41. <property name="ds" ref="dataSource"></property>   
  42. </bean>   
  43.   
  44. <!-- 采用@Transactional注解方式来使用事务 -->   
  45. <tx:annotation-driven transaction-manager="txManager"/>   
  46. </beans>
相关文章
相关标签/搜索