database.xml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  6. <bean id="dataSource" name="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  7. scope="singleton">
  8. <property name="driverClassName" value="${dataSource.driverClassName}" />
  9. <property name="url" value="${dataSource.url}" />
  10. <property name="username" value="${dataSource.username}"/>
  11. <property name="password" value="${dataSource.password}"/>
  12. <property name="validationQuery" value="SELECT 1 from dual"/>
  13. <property name="testOnBorrow" value="false"/>
  14. <property name="testWhileIdle" value ="true"/>
  15. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  16. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  17. <property name="minEvictableIdleTimeMillis" value="300000" />
  18. <!--每次检测时,需要检测多少个数据连接,一般设置为与最大连接数一样,这样就可以检测完所有的连接-->
  19. <property name="numTestsPerEvictionRun" value="20" />
  20. <property name="initialSize" value="10"/>
  21. <property name="maxActive" value="20"/>
  22. <property name="maxWait" value="60000"/>
  23. <!--是否在数据库连接请求量大的时候,如总数50,当前已请求了49个,所剩不多了,检测那些执行时间久的连接-->
  24. <property name="removeAbandoned" value="true"/>
  25. <!--归还连接时执行validationQuery检测连接是否有效-->
  26. <property name="testOnReturn" value="true" />
  27. </bean>
  28. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
  29. scope="singleton" lazy-init="true">
  30. <property name="configLocation"
  31. value="classpath:com/startup/minpay/frame/jdbc/mybatisConfigure.xml"></property>
  32. <property name="dataSource" ref="dataSource" />
  33. <property name="mapperLocations">
  34. <list>
  35. <value>classpath:com/minpay/db/table/mapper/*.xml</value>
  36. <value>classpath:com/minpay/db/table/own/mapper/*.xml</value>
  37. </list>
  38. </property>
  39. <property name="typeAliasesPackage" value="com.minpay.db" />
  40. </bean>
  41. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
  42. scope="singleton" lazy-init="true">
  43. <property name="basePackage" value="com.min.xxpro.db" />
  44. </bean>
  45. <bean id="transactionFactory"
  46. class="org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory"
  47. scope="singleton" lazy-init="true"/>
  48. <bean id="databaseManager" class="com.startup.minpay.frame.jdbc.MINDataBaseManager"
  49. scope="singleton">
  50. <constructor-arg>
  51. <ref bean="sqlSessionFactory" />
  52. </constructor-arg>
  53. <constructor-arg>
  54. <ref bean="transactionFactory" />
  55. </constructor-arg>
  56. </bean>
  57. </beans>