applicationContext.xml 6.8 KB

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