rtrh-hibernate.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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" xmlns:aop="http://www.springframework.org/schema/aop"
  4. xmlns:tx="http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  6. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  7. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
  8. <bean id="sessionFactory"
  9. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  10. <property name="dataSource" ref="poolDataSource" />
  11. <property name="packagesToScan">
  12. <list>
  13. <!-- 通用模块 -->
  14. <value>classpath*:com.rtrh.common.modules.*.po</value>
  15. <!-- 核心插件 -->
  16. <value>classpath*:com.rtrh.core.plugins.*.po</value>
  17. <value>classpath*:com.rtrh.projects.modules.*.po</value>
  18. </list>
  19. </property>
  20. <property name="hibernateProperties">
  21. <value>
  22. <!-- 设置数据库方言 -->
  23. hibernate.dialect=org.hibernate.dialect.MySQLDialect
  24. <!-- 设置自动创建|更新|验证数据库表结构 -->
  25. hibernate.hbm2ddl.auto=update
  26. <!-- 是否在控制台显示sql -->
  27. hibernate.show_sql=true
  28. <!-- 是否格式化sql,优化显示 -->
  29. hibernate.format_sql=true
  30. <!-- 是否开启二级缓存 -->
  31. hibernate.cache.use_second_level_cache=true
  32. <!-- 是否开启查询缓存 -->
  33. hibernate.cache.use_query_cache=false
  34. <!-- 缓存region -->
  35. hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
  36. <!-- 数据库批量查询最大数 -->
  37. hibernate.jdbc.fetch_size=50
  38. <!-- 数据库批量更新、添加、删除操作最大数 -->
  39. hibernate.jdbc.batch_size=50
  40. <!-- 是否自动提交事务 -->
  41. hibernate.connection.autocommit=false
  42. <!-- 指定hibernate在何时释放JDBC连接 -->
  43. hibernate.connection.release_mode=auto
  44. <!-- 创建session方式 hibernate4.x 的方式 -->
  45. hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
  46. <!-- javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包
  47. 所以把它设置为none即可 -->
  48. javax.persistence.validation.mode=none
  49. </value>
  50. </property>
  51. <property name="entityInterceptor">
  52. <ref bean="entityInterceptor" />
  53. </property>
  54. <property name="mappingLocations">
  55. <list>
  56. <!-- 通用模块 -->
  57. <value>classpath*:/com/rtrh/common/modules/*/po/*.hbm.xml</value>
  58. <!-- 核心插件 -->
  59. <value>classpath*:/com/rtrh/core/plugins/*/po/*.hbm.xml</value>
  60. <value>classpath*:/com/rtrh/projects/modules/*/po/*.hbm.xml</value>
  61. </list>
  62. </property>
  63. </bean>
  64. <bean id="eventListener" class="com.rtrh.core.repository.hibernate.EventListener" />
  65. <bean id="entityInterceptor" class="com.rtrh.core.repository.hibernate.EntityInterceptor" />
  66. <bean id="transactionManager"
  67. class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  68. <property name="sessionFactory" ref="sessionFactory" />
  69. </bean>
  70. <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
  71. <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
  72. <aop:aspectj-autoproxy/>
  73. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  74. <tx:attributes>
  75. <tx:method name="*" rollback-for="java.lang.Exception" />
  76. <tx:method name="*" rollback-for="java.lang.RuntimeException" />
  77. <tx:method name="create*" propagation="REQUIRED" />
  78. <tx:method name="save*" propagation="REQUIRED" />
  79. <tx:method name="add*" propagation="REQUIRED" />
  80. <tx:method name="update*" propagation="REQUIRED" />
  81. <tx:method name="remove*" propagation="REQUIRED" />
  82. <tx:method name="del*" propagation="REQUIRED" />
  83. <tx:method name="import*" propagation="REQUIRED" />
  84. </tx:attributes>
  85. </tx:advice>
  86. <aop:config proxy-target-class="true">
  87. <!-- 核心插件事务 -->
  88. <aop:pointcut id="corePluginServiceMethods" expression="execution(* com.rtrh.core.plugins..*.*(..))" />
  89. <!-- 通用模块事务 -->
  90. <aop:pointcut id="commModulesServiceMethods" expression="execution(* com.rtrh.common.modules..*.*(..))" />
  91. <!-- 扩展模块事务 -->
  92. <aop:pointcut id="extModulesServiceMethods" expression="execution(* com.rtrh.ext.modules..*.*(..))" />
  93. <aop:pointcut id="projectsModulesServiceMethods" expression="execution(* com.rtrh.projects.modules..*.*(..))" />
  94. <aop:advisor advice-ref="txAdvice" pointcut-ref="corePluginServiceMethods" />
  95. <aop:advisor advice-ref="txAdvice" pointcut-ref="commModulesServiceMethods" />
  96. <aop:advisor advice-ref="txAdvice" pointcut-ref="extModulesServiceMethods" />
  97. <aop:advisor advice-ref="txAdvice" pointcut-ref="projectsModulesServiceMethods" />
  98. </aop:config>
  99. <!-- hibernate 缓存
  100. <bean id="cacheManagerEhcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
  101. <property name="configLocation">
  102. <value>classpath:/ehcache.xml</value>
  103. </property>
  104. <property name="shared" value="true"/>
  105. </bean>
  106. -->
  107. <!-- druid spring monitor setting -->
  108. <bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"/>
  109. <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
  110. <property name="patterns">
  111. <list>
  112. <value>com.rtrh.projects.*</value>
  113. </list>
  114. </property>
  115. </bean>
  116. <aop:config proxy-target-class="true">
  117. <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut"/>
  118. </aop:config>
  119. </beans>