ApplicationContext-dataSource.xml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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:aop="http://www.springframework.org/schema/aop"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/aop
  10. http://www.springframework.org/schema/aop/spring-aop.xsd
  11. http://www.springframework.org/schema/context
  12. http://www.springframework.org/schema/context/spring-context.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx.xsd
  15. ">
  16. <!-- ====================数据源1==================== -->
  17. <!-- sql会话模版 -->
  18. <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
  19. <constructor-arg ref="sqlSessionFactory" />
  20. </bean>
  21. <!-- 配置mybatis -->
  22. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  23. <property name="dataSource" ref="dataSource" />
  24. <property name="configLocation" value="classpath:mybatis1/mybatis-config.xml"></property>
  25. <!-- mapper扫描 -->
  26. <property name="mapperLocations" value="classpath:mybatis1/*/*.xml"></property>
  27. </bean>
  28. <!-- 阿里 druid数据库连接池 -->
  29. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
  30. <!-- 数据库基本信息配置 -->
  31. <property name="url" value="${url}" />
  32. <property name="username" value="${username}" />
  33. <property name="password" value="${password}" />
  34. <property name="driverClassName" value="${driverClassName}" />
  35. <property name="filters" value="${filters}" />
  36. <!-- 最大并发连接数 -->
  37. <property name="maxActive" value="${maxActive}" />
  38. <!-- 初始化连接数量 -->
  39. <property name="initialSize" value="${initialSize}" />
  40. <!-- 配置获取连接等待超时的时间 -->
  41. <property name="maxWait" value="${maxWait}" />
  42. <!-- 最小空闲连接数 -->
  43. <property name="minIdle" value="${minIdle}" />
  44. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  45. <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
  46. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  47. <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" />
  48. <property name="validationQuery" value="${validationQuery}" />
  49. <property name="testWhileIdle" value="${testWhileIdle}" />
  50. <property name="testOnBorrow" value="${testOnBorrow}" />
  51. <property name="testOnReturn" value="${testOnReturn}" />
  52. <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" />
  53. <!-- 打开removeAbandoned功能 -->
  54. <property name="removeAbandoned" value="${removeAbandoned}" />
  55. <!-- 1800秒,也就是30分钟 -->
  56. <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" />
  57. <!-- 关闭abanded连接时输出错误日志 -->
  58. <property name="logAbandoned" value="${logAbandoned}" />
  59. </bean>
  60. <!-- 事物处理 -->
  61. <aop:config>
  62. <aop:pointcut id="pc" expression="execution(* com.fh.service..*(..))" />
  63. <aop:advisor pointcut-ref="pc" advice-ref="txAdvice" />
  64. </aop:config>
  65. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  66. <tx:attributes>
  67. <tx:method name="delete*" propagation="REQUIRED" read-only="false"
  68. rollback-for="java.lang.Exception"/>
  69. <tx:method name="insert*" propagation="REQUIRED" read-only="false"
  70. rollback-for="java.lang.Exception" />
  71. <tx:method name="update*" propagation="REQUIRED" read-only="false"
  72. rollback-for="java.lang.Exception" />
  73. <tx:method name="save*" propagation="REQUIRED" read-only="false"
  74. rollback-for="java.lang.Exception" />
  75. </tx:attributes>
  76. </tx:advice>
  77. <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  78. <property name="dataSource" ref="dataSource"></property>
  79. </bean>
  80. <!-- ====================数据源2==================== -->
  81. <!-- <bean id="sqlSessionTemplate2" class="org.mybatis.spring.SqlSessionTemplate"> -->
  82. <!-- <constructor-arg ref="sqlSessionFactory2" /> -->
  83. <!-- </bean> -->
  84. <!-- <bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean"> -->
  85. <!-- <property name="dataSource" ref="dataSource2" /> -->
  86. <!-- <property name="configLocation" value="classpath:mybatis2/mybatis-config.xml"></property> -->
  87. <!-- <property name="mapperLocations" value="classpath:mybatis2/*/*.xml"></property> -->
  88. <!-- </bean> -->
  89. <!-- <bean id="dataSource2" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> -->
  90. <!-- <property name="url" value="${url2}" /> -->
  91. <!-- <property name="username" value="${username2}" /> -->
  92. <!-- <property name="password" value="${password2}" /> -->
  93. <!-- <property name="driverClassName" value="${driverClassName2}" /> -->
  94. <!-- <property name="filters" value="${filters2}" /> -->
  95. <!-- <property name="maxActive" value="${maxActive2}" /> -->
  96. <!-- <property name="initialSize" value="${initialSize2}" /> -->
  97. <!-- <property name="maxWait" value="${maxWait2}" /> -->
  98. <!-- <property name="minIdle" value="${minIdle2}" /> -->
  99. <!-- <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis2}" /> -->
  100. <!-- <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis2}" /> -->
  101. <!-- <property name="testWhileIdle" value="${testWhileIdle2}" /> -->
  102. <!-- <property name="testOnBorrow" value="${testOnBorrow2}" /> -->
  103. <!-- <property name="testOnReturn" value="${testOnReturn2}" /> -->
  104. <!-- <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements2}" /> -->
  105. <!-- <property name="removeAbandoned" value="${removeAbandoned2}" /> -->
  106. <!-- <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout2}" /> -->
  107. <!-- <property name="logAbandoned" value="${logAbandoned2}" /> -->
  108. <!-- </bean> -->
  109. <!-- <aop:config> -->
  110. <!-- <aop:pointcut id="pc2" expression="execution(* com.fh.service..*(..))" /> -->
  111. <!-- <aop:advisor pointcut-ref="pc2" advice-ref="txAdvice2" /> -->
  112. <!-- </aop:config> -->
  113. <!-- <tx:advice id="txAdvice2" transaction-manager="transactionManager2"> -->
  114. <!-- <tx:attributes> -->
  115. <!-- <tx:method name="delete*" propagation="REQUIRED" read-only="false" -->
  116. <!-- rollback-for="java.lang.Exception"/> -->
  117. <!-- <tx:method name="insert*" propagation="REQUIRED" read-only="false" -->
  118. <!-- rollback-for="java.lang.Exception" /> -->
  119. <!-- <tx:method name="update*" propagation="REQUIRED" read-only="false" -->
  120. <!-- rollback-for="java.lang.Exception" /> -->
  121. <!-- <tx:method name="save*" propagation="REQUIRED" read-only="false" -->
  122. <!-- rollback-for="java.lang.Exception" /> -->
  123. <!-- </tx:attributes> -->
  124. <!-- </tx:advice> -->
  125. <!-- <bean name="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> -->
  126. <!-- <property name="dataSource" ref="dataSource2"></property> -->
  127. <!-- </bean> -->
  128. <!-- QQ -->
  129. </beans>