applicationContext.xml 5.8 KB

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