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>
相關文章
相關標籤/搜索