applicationContext-jdbc.xml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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:tx="http://www.springframework.org/schema/tx"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xsi:schemaLocation="
  8. http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://www.springframework.org/schema/tx
  11. http://www.springframework.org/schema/tx/spring-tx.xsd
  12. http://www.springframework.org/schema/context
  13. http://www.springframework.org/schema/context/spring-context.xsd
  14. http://www.springframework.org/schema/aop
  15. http://www.springframework.org/schema/aop/spring-aop.xsd">
  16. <!-- 引入jdbc配置文件 -->
  17. <context:property-placeholder location="classpath:jdbc.properties" />
  18. <!-- 连接池配置 -->
  19. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  20. <!-- 基本属性 url、user、password -->
  21. <property name="driverClassName" value="${jdbc.driver}" />
  22. <property name="url" value="${jdbc.url}" />
  23. <property name="username" value="${jdbc.username}" />
  24. <property name="password" value="${jdbc.password}" />
  25. <!-- 配置初始化大小、最小、最大 -->
  26. <property name="initialSize" value="1" />
  27. <property name="minIdle" value="1" />
  28. <property name="maxActive" value="20" />
  29. <!-- 配置获取连接等待超时的时间 -->
  30. <property name="maxWait" value="60000" />
  31. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  32. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  33. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  34. <property name="minEvictableIdleTimeMillis" value="300000" />
  35. <!-- -->
  36. <property name="validationQuery" value="SELECT 1" />
  37. <property name="testWhileIdle" value="true" />
  38. <property name="testOnBorrow" value="false" />
  39. <property name="testOnReturn" value="false" />
  40. <!-- 配置监控统计拦截的filters -->
  41. <property name="filters" value="stat" />
  42. </bean>
  43. <!-- 为Mybatis创建SqlSessionFactory,同时指定数据源 -->
  44. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  45. <property name="dataSource" ref="dataSource" />
  46. <property name="configLocation" value="classpath:mybatis-config.xml" />
  47. <property name="mapperLocations" value="classpath:com/zheng/cms/dao/mapper/*Mapper.xml" />
  48. </bean>
  49. <!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->
  50. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  51. <property name="basePackage" value="com.zheng.cms.dao.mapper" />
  52. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  53. </bean>
  54. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  55. <property name="dataSource" ref="dataSource" />
  56. </bean>
  57. <!-- 启动注解事务 -->
  58. <tx:annotation-driven transaction-manager="transactionManager"/>
  59. </beans>