applicationContext.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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:p="http://www.springframework.org/schema/p"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xmlns:task="http://www.springframework.org/schema/task"
  8. xmlns:jee="http://www.springframework.org/schema/jee"
  9. xmlns:tx="http://www.springframework.org/schema/tx"
  10. xsi:schemaLocation="
  11. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  12. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  13. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  14. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
  15. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
  16. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
  17. <!-- 设置需要进行Spring注解扫描的类包 -->
  18. <context:component-scan base-package="com.happy" />
  19. <!-- 配置数据源 -->
  20. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  21. <!--<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>-->
  22. <!--<property name="url" value="jdbc:mysql://192.168.161.220:3306/bigdata?useCursorFetch=true&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;serverTimezone=UTC"></property>-->
  23. <!--<property name="password" value="root"></property>-->
  24. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  25. <property name="url" value="jdbc:mysql://6.205.66.5:3306/bigdata?useCursorFetch=true&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"></property>
  26. <property name="password" value="Ro0!ot_369!"></property>
  27. <property name="username" value="root"></property>
  28. <!-- 配置获取连接等待超时的时间 -->
  29. <property name="maxWait" value="60000" />
  30. <property name="maxActive" value="20" />
  31. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  32. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  33. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  34. <property name="minEvictableIdleTimeMillis" value="90000" />
  35. <!-- 关闭长时间不使用的连接,防止连接池泄漏 -->
  36. <property name="removeAbandoned" value="true" />
  37. <!-- 打开removeAbandoned功能 -->
  38. <property name="removeAbandonedTimeout" value="600" /> <!-- 秒-->
  39. <property name="validationQuery" value="SELECT 'x'" />
  40. <property name="testWhileIdle" value="true" />
  41. <property name="testOnBorrow" value="false" />
  42. <property name="testOnReturn" value="false" />
  43. <!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用) -->
  44. <property name="poolPreparedStatements" value="true" />
  45. <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
  46. <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->
  47. <property name="filters" value="stat" />
  48. </bean>
  49. <!-- 配置Jdbc模板 -->
  50. <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" scope="prototype">
  51. <constructor-arg ref="dataSource"></constructor-arg>
  52. </bean>
  53. <!-- 配置事务管理器 -->
  54. <bean id="transactionManager" scope="prototype"
  55. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  56. <property name="dataSource" ref="dataSource" />
  57. </bean>
  58. <!-- 配置事务通知属性 -->
  59. <tx:advice id="txAdvice" transaction-manager="transactionManager" >
  60. <!-- 定义事务传播属性 -->
  61. <tx:attributes>
  62. <tx:method name="insert*" propagation="REQUIRED"/>
  63. <tx:method name="count*" propagation="REQUIRED"/>
  64. <tx:method name="update*" propagation="REQUIRED"/>
  65. <tx:method name="edit*" propagation="REQUIRED"/>
  66. <tx:method name="save*" propagation="REQUIRED"/>
  67. <tx:method name="add*" propagation="REQUIRED"/>
  68. <tx:method name="new*" propagation="REQUIRED"/>
  69. <tx:method name="set*" propagation="REQUIRED"/>
  70. <tx:method name="remove*" propagation="REQUIRED"/>
  71. <tx:method name="delete*" propagation="REQUIRED"/>
  72. <tx:method name="change*" propagation="REQUIRED"/>
  73. <tx:method name="get*" read-only="true" />
  74. <tx:method name="find*" read-only="true" />
  75. <tx:method name="load*" read-only="true" />
  76. <tx:method name="*" propagation="REQUIRED" />
  77. </tx:attributes>
  78. </tx:advice>
  79. <!-- 配置事务切面 -->
  80. <aop:config>
  81. <!-- 配置切点 -->
  82. <aop:pointcut id="serviceOperation"
  83. expression="execution(* com.happy.service.*.*(..))" />
  84. <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
  85. </aop:config>
  86. <!-- 配置定时任务 -->
  87. <task:annotation-driven />
  88. <task:scheduler id="dataScheduler" pool-size="5"/>
  89. </beans>