applicationContext.xml 4.8 KB

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