mybatis.xml 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  4. xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  8. http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
  9. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
  10. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  11. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
  12. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"
  13. default-lazy-init="true">
  14. <!-- MyBatis begin -->
  15. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  16. <property name="dataSource" ref="dataSource"/>
  17. <property name="typeAliasesPackage" value="com.jeeplus"/>
  18. <property name="typeAliasesSuperType" value="com.jeeplus.common.persistence.BaseEntity"/>
  19. <property name="mapperLocations" value="classpath:/mappings/**/*.xml"/>
  20. <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
  21. </bean>
  22. <!-- 扫描basePackage下所有以@MyBatisDao注解的接口 -->
  23. <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  24. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  25. <property name="basePackage" value="com.jeeplus"/>
  26. <property name="annotationClass" value="com.jeeplus.common.persistence.annotation.MyBatisDao"/>
  27. </bean>
  28. <!-- 定义事务 -->
  29. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  30. <property name="dataSource" ref="dataSource" />
  31. </bean>
  32. <!-- 配置 Annotation 驱动,扫描@Transactional注解的类定义事务 -->
  33. <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
  34. <!-- MyBatis end -->
  35. <!-- 数据源配置, 使用 BoneCP 数据库连接池 -->
  36. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  37. <!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
  38. <property name="driverClassName" value="${jdbc.driver}" />
  39. <!-- 基本属性 url、user、password -->
  40. <property name="url" value="${jdbc.url}" />
  41. <property name="username" value="${jdbc.username}" />
  42. <property name="password" value="${jdbc.password}" />
  43. <!-- 配置初始化大小、最小、最大 -->
  44. <property name="initialSize" value="${jdbc.pool.init}" />
  45. <property name="minIdle" value="${jdbc.pool.minIdle}" />
  46. <property name="maxActive" value="${jdbc.pool.maxActive}" />
  47. <!-- 配置获取连接等待超时的时间 -->
  48. <property name="maxWait" value="60000" />
  49. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  50. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  51. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  52. <property name="minEvictableIdleTimeMillis" value="300000" />
  53. <property name="validationQuery" value="${jdbc.testSql}" />
  54. <property name="testWhileIdle" value="true" />
  55. <property name="testOnBorrow" value="false" />
  56. <property name="testOnReturn" value="false" />
  57. <!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用)
  58. <property name="poolPreparedStatements" value="true" />
  59. <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> -->
  60. <!-- 配置监控统计拦截的filters -->
  61. <property name="filters" value="stat" />
  62. </bean>
  63. </beans>