spring_dao.xml 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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:util="http://www.springframework.org/schema/util"
  5. xmlns:tx="http://www.springframework.org/schema/tx"
  6. xmlns:p="http://www.springframework.org/schema/p"
  7. xmlns:mvc="http://www.springframework.org/schema/mvc"
  8. xmlns:context="http://www.springframework.org/schema/context"
  9. xmlns:aop="http://www.springframework.org/schema/aop"
  10. xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
  11. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  12. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
  13. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
  14. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
  15. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
  16. <!-- 指定外部的数据库信息配置文件,文件中保存用户名、密码等信息 -->
  17. <context:property-placeholder
  18. file-encoding="UTF-8" location="classpath:database/db.properties" />
  19. <!-- 数据源配置,使用 Druid -->
  20. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
  21. init-method="init" destroy-method="close">
  22. <!-- 基本属性driverClassName、 url、user、password -->
  23. <property name="driverClassName" value="${jdbc.driverClassName}"></property>
  24. <property name="url" value="${jdbc.url}" />
  25. <property name="username" value="${jdbc.username}" />
  26. <property name="password" value="${jdbc.password}" />
  27. <!-- 配置初始化大小、最小、最大 -->
  28. <property name="initialSize" value="1" />
  29. <property name="minIdle" value="1" />
  30. <property name="maxActive" value="20" />
  31. <!-- 配置获取连接等待超时的时间 -->
  32. <property name="maxWait" value="3000" />
  33. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  34. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  35. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  36. <property name="minEvictableIdleTimeMillis" value="300000" />
  37. <property name="validationQuery" value="SELECT 'x'" />
  38. <property name="testWhileIdle" value="true" />
  39. <property name="testOnBorrow" value="false" />
  40. <property name="testOnReturn" value="false" />
  41. <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
  42. <property name="poolPreparedStatements" value="false" />
  43. <property name="maxPoolPreparedStatementPerConnectionSize"
  44. value="20" />
  45. <!-- 配置监控统计拦截的filters -->
  46. <property name="filters" value="stat" />
  47. </bean>
  48. <!-- 以下是Mybatis集成到Spring的设置 -->
  49. <!-- 创建sqlSessinFactory -->
  50. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  51. <!-- 加载mybatis的配置文件 -->
  52. <property name="configLocation" value="classpath:mybatis/mybatis.xml" />
  53. <!-- 指定数据源 -->
  54. <property name="dataSource" ref="dataSource" />
  55. </bean>
  56. <!-- 自动扫描Mapper -->
  57. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  58. <property name="basePackage" value="com.ncjt.ch.eg.qrcode.mapper;com.ncjt.ch.sm.mapper;com.ncjt.ch.sm.mapper.custom" />
  59. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  60. </bean>
  61. <context:annotation-config />
  62. </beans>