context-base.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx.xsd"
  15. default-lazy-init="false">
  16. <!-- DatabaseRecognizer: The key is database product name or its regular exp, and the value is to
  17. match the file name of spring/corebean/*-context-base.xml when the app startup -->
  18. <bean id="databaseRecognizer" class="com.primeton.dgs.kernel.core.web.springframework.DatabaseRecognizer">
  19. <property name="databaseNames">
  20. <map>
  21. <entry key="Microsoft SQL Server" value="SQLServer" />
  22. <entry key="DB2/.+" value="DB2" />
  23. <entry key="Oracle" value="Oracle" />
  24. <entry key="MySQL" value="MySQL" />
  25. <entry key="Teradata" value="Teradata" />
  26. <entry key="Informix Dynamic Server" value="Informix" />
  27. <entry key="GBase 8t V8.5 Database Server" value="Informix" />
  28. <entry key="KingbaseES" value="Kingbase" />
  29. <entry key="DM DBMS" value="DM" />
  30. <entry key="PostgreSQL" value="PostgreSQL"/>
  31. </map>
  32. </property>
  33. </bean>
  34. <!-- ============== DAO DEFINITIONS: HIBERNATE IMPLEMENTATIONS ================= -->
  35. <!-- 使用spring+hibernate处理oracle BLOB-->
  36. <bean id="sessionFactory" class="com.primeton.dgs.kernel.core.dao.hibernate.HibernateLocalSessionFactoryBean">
  37. <property name="databaseRecognizer" ref="databaseRecognizer" />
  38. <property name="dataSource" ref="dataSource" />
  39. <property name="mappingResources">
  40. <list >
  41. <value>META-INF/sqlxml/mysql/adapterSql.xml</value><!-- 加载hibernate模型配置文件,实际加载交由该具体类实现 -->
  42. </list>
  43. </property>
  44. <property name="hibernateProperties">
  45. <props>
  46. <prop key="hibernate.dialect">org.hibernate.dialect.MySQL57Dialect</prop>
  47. <prop key="hibernate.query.factory_class">org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory</prop>
  48. <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
  49. <prop key="hibernate.jdbc.batch_size">50</prop>
  50. <!-- <prop key="hibernate.jdbc.fetch_size">100</prop> --><!--由于oracle驱动的bug导致memory leak-->
  51. <prop key="hibernate.generate_statistics">true</prop>
  52. <prop key="hibernate.show_sql">false</prop>
  53. <prop key="hibernate.format_sql">false</prop>
  54. </props>
  55. </property>
  56. </bean>
  57. <bean id="hibernateDao" abstract="true">
  58. <property name="sessionFactory" ref="sessionFactory" />
  59. <property name="dataSource" ref="dataSource" />
  60. </bean>
  61. <bean id="seqService" class="com.primeton.dgs.kernel.common.app.base.bs.SequenceServiceImpl">
  62. </bean>
  63. <bean id="baseSequence" class="com.primeton.dgs.kernel.common.app.base.bs.SequenceServiceImpl"></bean>
  64. <bean id="daservice"
  65. class="com.primeton.dgs.kernel.core.dao.impl.DAOServiceImpl"
  66. parent="hibernateDao" />
  67. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  68. <property name="dataSource" ref="dataSource" />
  69. </bean>
  70. <bean id="statementSessionFactory" class="com.primeton.dgs.kernel.core.dao.hibernate.HibernateStatementSessionFactoryBean"
  71. init-method="init" destroy-method="destroy">
  72. <!-- 加载SQL资源文件,实际加载交由该具体类实现 -->
  73. <property name="statementResources" value="" />
  74. </bean>
  75. <!--JPA 配置 start-->
  76. <bean id="persistenceProvider" class="org.hibernate.jpa.HibernatePersistenceProvider"/>
  77. <!-- JPA entityManagerFactory -->
  78. <bean id="entityManagerFactory" class="com.primeton.dgs.kernel.core.dao.jpa.JpaContainerEntityManagerFactoryBean">
  79. <!-- 指定数据源 -->
  80. <property name="databaseRecognizer" ref="databaseRecognizer" />
  81. <property name="dataSource" ref="dataSource"/>
  82. <property name="persistenceUnitName" value="persistenceUnit"/>
  83. <property name="persistenceProvider" ref="persistenceProvider"/>
  84. <!-- 指定Entity实体类包路径 -->
  85. <property name="packagesToScan">
  86. <array>
  87. <value>com.primeton.dgs.entity</value>
  88. <value>org.gocom.coframe.model</value>
  89. </array>
  90. </property>
  91. <!-- 指定Jpa持久化实现厂商类,根据 databaseRecognizer 配置,大多数知名数据库都能自动配置。国产数据库或者其他无法确认的数据需要设置
  92. <property name="jpaVendorAdapter">
  93. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
  94. <property name="generateDdl" value="false"/>
  95. <property name="database" value="MYSQL"/>
  96. <property name="databasePlatform" value="org.hibernate.dialect.MySQL57Dialect"/>
  97. <property name="showSql" value="false"/>
  98. </bean>
  99. </property>
  100. -->
  101. <!-- 指定JPA属性-->
  102. <property name="jpaPropertyMap">
  103. <map>
  104. <entry key="hibernate.show_sql" value="true" />
  105. <entry key="hibernate.query.substitutions" value="true 1, false 0"/>
  106. <entry key="hibernate.default_batch_fetch_size" value="16"/>
  107. <entry key="hibernate.max_fetch_depth" value="2"/>
  108. <entry key="hibernate.generate_statistics" value="false"/>
  109. <entry key="hibernate.bytecode.use_reflection_optimizer" value="true"/>
  110. <entry key="hibernate.cache.use_query_cache" value="false"/>
  111. <entry key="hibernate.cache.use_second_level_cache" value="false"/>
  112. <entry key="hibernate.enable_lazy_load_no_trans" value="true"/>
  113. <!--数据库字段名称映射规则 acb_id自动转abcId-->
  114. <entry key="hibernate.physical_naming_strategy" value="org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy" />
  115. <entry key="hibernate.implicit_naming_strategy" value="org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl"/>
  116. <!--<entry key="hibernate.hbm2ddl.auto" value="validate"/>-->
  117. </map>
  118. </property>
  119. </bean>
  120. <context:annotation-config />
  121. <context:component-scan base-package="org.gocom.coframe.**" />
  122. <!-- 默认的事务管理器,支持 Hibernate。 JPA 见 TransactionManagerConfigurer -->
  123. <bean id="defTransactionManager"
  124. class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  125. <property name="dataSource" ref="dataSource" />
  126. <property name="sessionFactory" ref="sessionFactory" />
  127. </bean>
  128. <!-- Spring Context Helper -->
  129. <bean id="SpringContextHelper" class="com.primeton.dgs.kernel.core.common.SpringContextHelper" />
  130. <!-- Quartz针对不同的数据库有不同的配置在这里 -->
  131. <bean id="schedulerDelegate" abstract="true">
  132. <property name="quartzProperties">
  133. <props>
  134. </props>
  135. </property>
  136. </bean>
  137. <!--
  138. 消息服务,用于事件发布,如采集完成,发布事件:获得事件后更新缓存、汇总分析立即执行等
  139. add zhaopx at: 2019/11/11
  140. -->
  141. <bean id="eventMessageService" class="com.primeton.dgs.kernel.core.message.MessageService"
  142. init-method="init" destroy-method="shutdown">
  143. </bean>
  144. </beans>