ApplicationContext-dataSource.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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:mybatis/mybatis-config.xml"></property>
  25. <!-- mapper扫描 -->
  26. <property name="mapperLocations" value="classpath:mybatis/*/*.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.zhcs.dt.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. <!--
  82. <bean id="sqlSessionTemplate2" class="org.mybatis.spring.SqlSessionTemplate">
  83. <constructor-arg ref="sqlSessionFactory2" />
  84. </bean>
  85. <bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
  86. <property name="dataSource" ref="dataSource2" />
  87. <property name="configLocation" value="classpath:mybatis2/mybatis-config.xml"></property>
  88. <property name="mapperLocations" value="classpath:mybatis2/*/*.xml"></property>
  89. </bean>
  90. <bean id="dataSource2" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
  91. <property name="url" value="${url2}" />
  92. <property name="username" value="${username2}" />
  93. <property name="password" value="${password2}" />
  94. <property name="driverClassName" value="${driverClassName2}" />
  95. <property name="filters" value="${filters2}" />
  96. <property name="maxActive" value="${maxActive2}" />
  97. <property name="initialSize" value="${initialSize2}" />
  98. <property name="maxWait" value="${maxWait2}" />
  99. <property name="minIdle" value="${minIdle2}" />
  100. <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis2}" />
  101. <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis2}" />
  102. <property name="validationQuery" value="${validationQuery2}" />
  103. <property name="testWhileIdle" value="${testWhileIdle2}" />
  104. <property name="testOnBorrow" value="${testOnBorrow2}" />
  105. <property name="testOnReturn" value="${testOnReturn2}" />
  106. <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements2}" />
  107. <property name="removeAbandoned" value="${removeAbandoned2}" />
  108. <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout2}" />
  109. <property name="logAbandoned" value="${logAbandoned2}" />
  110. </bean>
  111. <aop:config>
  112. <aop:pointcut id="pc2" expression="execution(* com.zhcs.dt.service..*(..))" />
  113. <aop:advisor pointcut-ref="pc2" advice-ref="txAdvice2" />
  114. </aop:config>
  115. <tx:advice id="txAdvice2" transaction-manager="transactionManager2">
  116. <tx:attributes>
  117. <tx:method name="delete*" propagation="REQUIRED" read-only="false"
  118. rollback-for="java.lang.Exception"/>
  119. <tx:method name="insert*" propagation="REQUIRED" read-only="false"
  120. rollback-for="java.lang.Exception" />
  121. <tx:method name="update*" propagation="REQUIRED" read-only="false"
  122. rollback-for="java.lang.Exception" />
  123. <tx:method name="save*" propagation="REQUIRED" read-only="false"
  124. rollback-for="java.lang.Exception" />
  125. </tx:attributes>
  126. </tx:advice>
  127. <bean name="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  128. <property name="dataSource" ref="dataSource2"></property>
  129. </bean>
  130. -->
  131. <!-- QQ313596790 -->
  132. </beans>