spring-mvc-hibernate.xml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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:context="http://www.springframework.org/schema/context"
  4. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
  5. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  8. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  10. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
  11. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"
  12. default-autowire="byName" default-lazy-init="false">
  13. <!-- 自动扫描dao和service包(自动注入) -->
  14. <context:component-scan base-package="org.jeecgframework.easypoi.*" />
  15. <context:component-scan base-package="org.jeecgframework.core.common.dao.*" />
  16. <context:component-scan base-package="org.jeecgframework.core.common.service.*" />
  17. <context:component-scan base-package="cn.com.lzt.*"/>
  18. <context:component-scan base-package="com.xcgl.*"/>
  19. <context:component-scan base-package="com.jeecg.*">
  20. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  21. </context:component-scan>
  22. <!-- 加载service,此时要排除要controller,因为controller已经spring-mvc中加载过了 -->
  23. <context:component-scan base-package="org.jeecgframework.web.*">
  24. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  25. </context:component-scan>
  26. <!-- 引入属性文件 -->
  27. <context:property-placeholder location="classpath:dbconfig.properties,classpath:redis.properties,classpath:mq.properties" />
  28. <!-- 配置数据源1 -->
  29. <bean name="dataSource_jeecg" class="com.alibaba.druid.pool.DruidDataSource"
  30. init-method="init" destroy-method="close">
  31. <property name="url" value="${jdbc.url.jeecg}" />
  32. <property name="username" value="${jdbc.username.jeecg}" />
  33. <property name="password" value="${jdbc.password.jeecg}" />
  34. <!-- 初始化连接大小 -->
  35. <property name="initialSize" value="0" />
  36. <!-- 连接池最大使用连接数量 -->
  37. <property name="maxActive" value="20" />
  38. <!-- 连接池最大空闲
  39. <property name="maxIdle" value="20" />
  40. -->
  41. <!-- 连接池最小空闲 -->
  42. <property name="minIdle" value="5" />
  43. <!-- 获取连接最大等待时间 -->
  44. <property name="maxWait" value="60000" />
  45. <!--
  46. <property name="poolPreparedStatements" value="true" />
  47. <property name="maxPoolPreparedStatementPerConnectionSize" value="33" />
  48. -->
  49. <property name="validationQuery" value="${validationQuery.sqlserver}" />
  50. <property name="testOnBorrow" value="false" />
  51. <property name="testOnReturn" value="false" />
  52. <property name="testWhileIdle" value="true" />
  53. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  54. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  55. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  56. <property name="minEvictableIdleTimeMillis" value="25200000" />
  57. <!-- 打开removeAbandoned功能 -->
  58. <property name="removeAbandoned" value="false" />
  59. <!-- 1800秒,也就是30分钟 -->
  60. <property name="removeAbandonedTimeout" value="3600" />
  61. <!-- 关闭abanded连接时输出错误日志 -->
  62. <property name="logAbandoned" value="true" />
  63. <!-- 开启Druid的监控统计功能 -->
  64. <property name="filters" value="stat" />
  65. <!--<property name="filters" value="mergeStat" /> -->
  66. <!-- Oracle连接是获取字段注释 -->
  67. <property name="connectProperties">
  68. <props>
  69. <prop key="remarksReporting">true</prop>
  70. </props>
  71. </property>
  72. </bean>
  73. <!-- 数据源集合 -->
  74. <bean id="dataSource"
  75. class="org.jeecgframework.core.extend.datasource.DynamicDataSource">
  76. <property name="targetDataSources">
  77. <map key-type="org.jeecgframework.core.extend.datasource.DataSourceType">
  78. <entry key="dataSource_jeecg" value-ref="dataSource_jeecg" />
  79. <!-- <entry key="mapdataSource" value-ref="mapdataSource" /> -->
  80. </map>
  81. </property>
  82. <property name="defaultTargetDataSource" ref="dataSource_jeecg" />
  83. </bean>
  84. <bean id="sessionFactory"
  85. class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  86. <property name="dataSource" ref="dataSource" />
  87. <property name="entityInterceptor" ref="hiberAspect" />
  88. <property name="hibernateProperties">
  89. <props>
  90. <!--<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> -->
  91. <prop key="hibernate.dialect">${hibernate.dialect}</prop>
  92. <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
  93. <prop key="hibernate.show_sql">false</prop>
  94. <prop key="hibernate.format_sql">false</prop>
  95. <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
  96. <prop key="hibernate.connection.release_mode">after_transaction</prop>
  97. </props>
  98. </property>
  99. <!-- 注解方式配置 -->
  100. <property name="packagesToScan">
  101. <list>
  102. <value>org.jeecgframework.web.system.pojo.*</value>
  103. <value>org.jeecgframework.web.test.entity.*</value>
  104. <value>org.jeecgframework.web.autoform.*</value>
  105. <value>org.jeecgframework.web.cgform.entity.*</value>
  106. <value>org.jeecgframework.web.cgreport.entity.*</value>
  107. <value>org.jeecgframework.web.cgdynamgraph.entity.*</value>
  108. <value>org.jeecgframework.web.graphreport.entity.*</value>
  109. <value>org.jeecgframework.web.system.sms.*</value>
  110. <value>com.jeecg.*</value>
  111. <value>jeecg.workflow.entity.*</value>
  112. <value>org.jeecgframework.workflow.*</value>
  113. <value>cn.com.lzt.*</value>
  114. <value>com.xcgl.*</value>
  115. </list>
  116. </property>
  117. </bean>
  118. <!-- JDBC配置 -->
  119. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  120. <property name="dataSource" ref="dataSource"/>
  121. </bean>
  122. <!-- JDBC配置 -->
  123. <bean id="namedParameterJdbcTemplate"
  124. class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
  125. <constructor-arg ref="dataSource" />
  126. </bean>
  127. <!-- 配置事物管理器,在*ServiceImpl里写@Transactional就可以启用事物管理 -->
  128. <!-- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">-->
  129. <!-- <property name="dataSource" ref="dataSource" />-->
  130. <!-- <property name="nestedTransactionAllowed" value="true"/>-->
  131. <!-- </bean>-->
  132. <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  133. <property name="sessionFactory" ref="sessionFactory"/>
  134. <property name="dataSource" ref="dataSource"/>
  135. </bean>
  136. <tx:annotation-driven transaction-manager="transactionManager" />
  137. <!-- JSR303 Validator定义 -->
  138. <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
  139. </beans>