dataSource.xml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:tx="http://www.springframework.org/schema/tx"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/tx
  8. http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
  9. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  10. <property name="url" value="${jdbc.url}" />
  11. <property name="driverClassName" value="${jdbc.driver}" />
  12. <property name="maxActive" value="${pool.maxPoolSize}" />
  13. <property name="username" value="${jdbc.username}" />
  14. <property name="password" value="${jdbc.password}" />
  15. <!-- 超过时间限制是否回收 -->
  16. <property name="removeAbandoned" value="true" />
  17. <!-- 超时时间;单位为秒。180秒=3分钟 -->
  18. <property name="removeAbandonedTimeout" value="${pool.removeAbandonedTimeout}" />
  19. <!-- 配置获取连接等待超时的时间 -->
  20. <property name="maxWait" value="${pool.maxWait}" />
  21. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  22. <property name="timeBetweenEvictionRunsMillis" value="${pool.timeBetweenEvictionRunsMillis}" />
  23. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  24. <property name="minEvictableIdleTimeMillis" value="${pool.minEvictableIdleTimeMillis}" />
  25. <property name="validationQuery" value="${pool.validationQuery} " />
  26. <property name="testWhileIdle" value="true" />
  27. <property name="testOnBorrow" value="false" />
  28. <property name="testOnReturn" value="false" />
  29. </bean>
  30. <!-- 事务 控制 begin -->
  31. <bean name="transactionManager"
  32. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  33. <property name="dataSource" ref="dataSource"></property>
  34. </bean>
  35. <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" order="10"/>
  36. <!-- 事务 控制 end -->
  37. <!-- 自动扫描mapping文件 start -->
  38. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  39. <property name="dataSource" ref="dataSource" />
  40. <property name="configLocation" value="classpath:mybatis-config.xml" />
  41. <!--<property name="mapperLocations" value="classpath*:com/edu/dao/**/*Mapper.xml"/>-->
  42. <property name="mapperLocations">
  43. <list>
  44. <!-- 表示在com/hywin包或以下所有目录中,以-Mapper.xml结尾所有文件 -->
  45. <value>classpath*:com/edu/dao/**/*.xml</value>
  46. </list>
  47. </property>
  48. <property name="typeAliasesSuperType" value="com.edu.base.BaseEntity" />
  49. <property name="configurationProperties">
  50. <props>
  51. <prop key="dialect">mysql</prop>
  52. </props>
  53. </property>
  54. <property name="plugins">
  55. <list>
  56. <bean class="com.edu.mybatis.SqlInterceptor" />
  57. </list>
  58. </property>
  59. </bean>
  60. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  61. <property name="basePackage" value="com.edu.dao" />
  62. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  63. </bean>
  64. <!-- 自动扫描mapping文件 end -->
  65. </beans>