applicationContext.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:tx="http://www.springframework.org/schema/tx"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns="http://www.springframework.org/schema/beans"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/tx
  10. http://www.springframework.org/schema/tx/spring-tx.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/context
  14. http://www.springframework.org/schema/context/spring-context.xsd">
  15. <context:component-scan base-package="com.yc.education.service"/>
  16. <context:property-placeholder location="classpath:config.properties"/>
  17. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  18. <property name="driverClassName" value="${jdbc.driverClass}"/>
  19. <property name="url" value="${jdbc.url}"/>
  20. <property name="username" value="${jdbc.user}"/>
  21. <property name="password" value="${jdbc.password}"/>
  22. <property name="filters" value="stat"/>
  23. <!-- 最大链接数 -->
  24. <property name="maxActive" value="2000"/>
  25. <!-- 初始化链接 -->
  26. <property name="initialSize" value="10"/>
  27. <!-- 从池中取连接的最大等待时间,单位ms. -->
  28. <property name="maxWait" value="60000"/>
  29. <!-- 最小空闲连接 -->
  30. <property name="minIdle" value="1"/>
  31. <!-- 每一分钟运行一次空闲连接回收器 -->
  32. <property name="timeBetweenEvictionRunsMillis" value="60000"/>
  33. <!-- 池中的连接空闲6分钟后被回收 -->
  34. <property name="minEvictableIdleTimeMillis" value="300000"/>
  35. <!-- 超时时间;单位为秒。180秒=3分钟 -->
  36. <property name="removeAbandonedTimeout" value="180" />
  37. <!-- 关闭abanded连接时输出错误日志 -->
  38. <property name="logAbandoned" value="true" />
  39. <!-- 超过时间限制是否回收 -->
  40. <property name="removeAbandoned" value="true" />
  41. <property name="validationQuery" value="SELECT 'x'"/>
  42. <property name="testWhileIdle" value="true"/>
  43. <property name="testOnBorrow" value="false"/>
  44. <property name="testOnReturn" value="false"/>
  45. </bean>
  46. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  47. <!-- <property name="configLocation" value="classpath:mybatis-config.xml" /> -->
  48. <property name="dataSource" ref="dataSource"/>
  49. <property name="mapperLocations">
  50. <array>
  51. <value>classpath:mapper/*.xml</value>
  52. </array>
  53. </property>
  54. <property name="typeAliasesPackage" value="com.yc.education.model"/>
  55. <property name="plugins">
  56. <array>
  57. <bean class="com.github.pagehelper.PageHelper">
  58. <!-- 这里的几个配置主要演示如何使用,如果不理解,一定要去掉下面的配置 -->
  59. <property name="properties">
  60. <value>
  61. dialect=mysql
  62. reasonable=true
  63. supportMethodsArguments=true
  64. params=count=countSql
  65. autoRuntimeDialect=true
  66. </value>
  67. </property>
  68. </bean>
  69. </array>
  70. </property>
  71. </bean>
  72. <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
  73. <property name="basePackage" value="com.yc.education.mapper"/>
  74. <!-- 3.2.2版本新特性,markerInterface可以起到mappers配置的作用,详细情况需要看Marker接口类 -->
  75. <property name="markerInterface" value="com.yc.education.util.MyMapper"/>
  76. <!-- 通用Mapper通过属性注入进行配置,默认不配置时会注册Mapper<T>接口
  77. <property name="properties">
  78. <value>
  79. mappers=tk.mybatis.mapper.common.Mapper
  80. </value>
  81. </property>
  82. -->
  83. </bean>
  84. <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
  85. <constructor-arg index="0" ref="sqlSessionFactory"/>
  86. </bean>
  87. <aop:aspectj-autoproxy/>
  88. <aop:config>
  89. <aop:pointcut id="appService" expression="execution(* com.yc.education.service..*Service*.*(..))"/>
  90. <aop:advisor advice-ref="txAdvice" pointcut-ref="appService"/>
  91. </aop:config>
  92. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  93. <tx:attributes>
  94. <tx:method name="select*" read-only="true"/>
  95. <tx:method name="find*" read-only="true"/>
  96. <tx:method name="get*" read-only="true"/>
  97. <tx:method name="*"/>
  98. </tx:attributes>
  99. </tx:advice>
  100. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  101. <property name="dataSource" ref="dataSource"/>
  102. </bean>
  103. <!-- ...............................这个配置文件专门配置定时任务........................... -->
  104. <!-- 方式二:使用MethodInvokingJobDetailFactoryBean,任务类可以不实现Job接口,通过targetMethod指定调用方法-->
  105. <!-- 定义目标bean和bean中的方法 -->
  106. <!-- <bean id="SpringQtzJob" class="com.yc.education.controller.SupplierController"/>
  107. <bean id="SpringQtzJobMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
  108. <property name="targetObject">
  109. <ref bean="SpringQtzJob"/>
  110. </property>
  111. <property name="targetMethod"> 要执行的方法名称
  112. <value>execute</value>
  113. </property>
  114. </bean> -->
  115. <!-- 触发器
  116. <bean id="CronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
  117. <property name="jobDetail" ref="SpringQtzJobMethod"></property>
  118. <property name="cronExpression" value="0 0 0 * * ? *"></property>
  119. </bean> -->
  120. <!-- ======================== 调度工厂 ======================== -->
  121. <!-- <bean id="SpringJobSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  122. <property name="triggers">
  123. <list>
  124. <ref bean="CronTriggerBean"/>
  125. </list>
  126. </property>
  127. </bean> -->
  128. </beans>