applicationContext.xml 5.2 KB

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