mybatis-spring.xml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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" xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context.xsd
  9. http://www.springframework.org/schema/aop
  10. http://www.springframework.org/schema/aop/spring-aop.xsd
  11. http://www.springframework.org/schema/tx
  12. http://www.springframework.org/schema/tx/spring-tx.xsd">
  13. <!-- 配置数据源 测试数据库 mysql -h 192.168.1.87 -uroot -padmin123-->
  14. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  15. <!-- 基本属性 url、user、password -->
  16. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  17. <property name="url" value="jdbc:mysql://127.0.0.1:3306/efunbox_recmd" />
  18. <property name="username" value="root" />
  19. <property name="password" value="223732" />
  20. <property name="initialSize" value="1" />
  21. <property name="minIdle" value="1" />
  22. <property name="maxActive" value="20" />
  23. <property name="maxWait" value="60000" />
  24. <!-- 超过时间限制是否回收 -->
  25. <property name="removeAbandoned" value="true" />
  26. <!-- 超过时间限制多长; -->
  27. <property name="removeAbandonedTimeout" value="180" />
  28. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  29. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  30. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  31. <property name="minEvictableIdleTimeMillis" value="300000" />
  32. <!-- 用来检测连接是否有效的sql,要求是一个查询语句-->
  33. <property name="validationQuery" value="SELECT 1" />
  34. <!-- 申请连接的时候检测 -->
  35. <property name="testWhileIdle" value="true" />
  36. <!-- 申请连接时执行validationQuery检测连接是否有效,配置为true会降低性能 -->
  37. <property name="testOnBorrow" value="false" />
  38. <!-- 归还连接时执行validationQuery检测连接是否有效,配置为true会降低性能 -->
  39. <property name="testOnReturn" value="false" />
  40. </bean>
  41. <!-- Mybatis文件 -->
  42. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  43. <property name="configLocation" value="classpath:mybatis-config.xml" />
  44. <property name="dataSource" ref="dataSource" />
  45. <!-- 映射文件路径 -->
  46. <!-- <property name="mapperLocations" value="cn/efunbox/mapping/*.xml" />-->
  47. </bean>
  48. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  49. <property name="basePackage" value="cn.efunbox.dao" />
  50. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  51. </bean>
  52. <!-- 事务管理器 -->
  53. <bean id="transactionManager"
  54. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  55. <property name="dataSource" ref="dataSource" />
  56. </bean>
  57. <tx:annotation-driven transaction-manager="transactionManager" />
  58. </beans>