applicationContext.xml 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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:tx="http://www.springframework.org/schema/tx"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xsi:schemaLocation="
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
  8. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  9. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
  10. <context:annotation-config />
  11. <context:component-scan base-package="com.how2java.tmall.service" />
  12. <!-- 导入数据库配置文件 -->
  13. <context:property-placeholder location="classpath:jdbc.properties"/>
  14. <!-- 配置数据库连接池 -->
  15. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  16. <!-- 基本属性 url、user、password -->
  17. <property name="url" value="${jdbc.url}" />
  18. <property name="username" value="${jdbc.username}" />
  19. <property name="password" value="${jdbc.password}" />
  20. <!-- 配置初始化大小、最小、最大 -->
  21. <property name="initialSize" value="1" />
  22. <property name="minIdle" value="1" />
  23. <property name="maxActive" value="20" />
  24. <!-- 配置获取连接等待超时的时间 -->
  25. <property name="maxWait" value="60000" />
  26. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  27. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  28. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  29. <property name="minEvictableIdleTimeMillis" value="300000" />
  30. <property name="validationQuery" value="SELECT 1" />
  31. <property name="testWhileIdle" value="true" />
  32. <property name="testOnBorrow" value="false" />
  33. <property name="testOnReturn" value="false" />
  34. <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
  35. <property name="poolPreparedStatements" value="true" />
  36. <property name="maxPoolPreparedStatementPerConnectionSize"
  37. value="20" />
  38. </bean>
  39. <!--Mybatis的SessionFactory配置-->
  40. <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
  41. <property name="typeAliasesPackage" value="com.how2java.tmall.pojo" />
  42. <property name="dataSource" ref="dataSource"/>
  43. <property name="mapperLocations" value="classpath:mapper/*.xml"/>
  44. <property name="plugins">
  45. <array>
  46. <bean class="com.github.pagehelper.PageInterceptor">
  47. <property name="properties">
  48. <value>
  49. </value>
  50. </property>
  51. </bean>
  52. </array>
  53. </property>
  54. </bean>
  55. <!--Mybatis的Mapper文件识别-->
  56. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  57. <property name="basePackage" value="com.how2java.tmall.mapper"/>
  58. </bean>
  59. <!--事务管理-->
  60. <tx:annotation-driven transaction-manager="transactionManager"/>
  61. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  62. <property name="dataSource" ref="dataSource" />
  63. </bean>
  64. </beans>