applicationContext.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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:jee="http://www.springframework.org/schema/jee"
  4. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  6. xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop"
  7. xmlns:repository="http://www.springframework.org/schema/data/repository"
  8. xmlns:mvc="http://www.springframework.org/schema/mvc"
  9. xsi:schemaLocation="
  10. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
  11. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  12. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
  13. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
  14. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
  15. http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
  16. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
  17. http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
  18. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  19. http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd"
  20. default-lazy-init="true">
  21. <description>Spring公共配置 </description>
  22. <context:property-placeholder
  23. ignore-resource-not-found="true" location="classpath*:spring/application.properties" />
  24. <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入. @Controller的Bean注入在spring-mvc.xml中自动注册 -->
  25. <context:component-scan base-package="com.xt.jygl">
  26. <context:exclude-filter type="annotation"
  27. expression="org.springframework.stereotype.Controller" />
  28. </context:component-scan>
  29. <bean id="propertiesGisReader"
  30. class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  31. <property name="locations">
  32. <list>
  33. <!--<value>classpath:param.properties</value>-->
  34. <value>/WEB-INF/config/gis.properties</value>
  35. </list>
  36. </property>
  37. </bean>
  38. <!-- Jpa Entity Manager 配置 -->
  39. <bean id="entityManagerFactory"
  40. class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  41. <property name="persistenceUnitName" value="persistence_unit_1" />
  42. <property name="dataSource" ref="dataSource" />
  43. <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
  44. <property name="packagesToScan" value="com.xt.jygl,com.xtframe" />
  45. <property name="jpaProperties">
  46. <props>
  47. <prop key="hibernate.dialect">${hibernate.dialect}</prop>
  48. <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy
  49. </prop>
  50. <prop key="hibernate.show_sql">false</prop>
  51. <prop key="hibernate.format_sql">false</prop>
  52. </props>
  53. </property>
  54. </bean>
  55. <bean id="hibernateConfuration" class="org.hibernate.cfg.Configuration">
  56. <property name="properties">
  57. <props>
  58. <prop key="hibernate.dialect">${hibernate.dialect}</prop>
  59. <prop key="hibernate.connection.driver_class">${jdbc.driver}</prop>
  60. <prop key="hibernate.connection.url">${jdbc.url}</prop>
  61. <prop key="hibernate.connection.username">${jdbc.username}</prop>
  62. <prop key="hibernate.connection.password">${jdbc.password}</prop>
  63. </props>
  64. </property>
  65. </bean>
  66. <bean id="hibernateJpaVendorAdapter"
  67. class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
  68. <!-- Spring Data Jpa配置 -->
  69. <jpa:repositories base-package="com.xt.jygl,com.xtframe.sec"
  70. transaction-manager-ref="transactionManager"
  71. entity-manager-factory-ref="entityManagerFactory"
  72. factory-class="com.xtframe.sec.common.SecRepositoryFactoryBean" />
  73. <!-- JPA 事务配置 -->
  74. <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  75. <property name="entityManagerFactory" ref="entityManagerFactory" />
  76. </bean>
  77. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  78. <tx:attributes>
  79. <tx:method name="add*" propagation="REQUIRED" />
  80. <tx:method name="delete*" propagation="REQUIRED" />
  81. <tx:method name="logic*" propagation="REQUIRED" />
  82. <tx:method name="update*" propagation="REQUIRED" />
  83. <tx:method name="save*" propagation="REQUIRED" />
  84. <tx:method name="submit*" propagation="REQUIRED" />
  85. <tx:method name="claim*" propagation="REQUIRED" />
  86. <tx:method name="create*" propagation="REQUIRED" />
  87. <tx:method name="complete*" propagation="REQUIRED" />
  88. <tx:method name="autoComplete*" propagation="REQUIRED" />
  89. <tx:method name="reject*" propagation="REQUIRED" />
  90. <tx:method name="change*" propagation="REQUIRED" />
  91. <tx:method name="sendMail" propagation="REQUIRED" />
  92. <tx:method name="reSubmit*" propagation="REQUIRED" />
  93. <tx:method name="do*" propagation="REQUIRED" />
  94. <tx:method name="*" propagation="SUPPORTS" read-only="true" />
  95. </tx:attributes>
  96. </tx:advice>
  97. <!-- Hibernate事务配置 -->
  98. <bean id="hibernate-transactionManager"
  99. class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  100. <property name="sessionFactory" ref="sessionFactory" />
  101. </bean>
  102. <!-- 使用annotation定义事务 -->
  103. <!--tx:annotation-driven transaction-manager="transactionManager"
  104. proxy-target-class="true" /-->
  105. <!--bean id="aspectBean" class="com.xtframe.TestAspect" />
  106. <aop:config>
  107. <aop:aspect id="TestAspect" ref="aspectBean">
  108. <aop:pointcut id="businessService"
  109. expression="execution(* (com.xt.jygl.common.service.JyglBaseService+).*(..))" />
  110. <aop:before pointcut-ref="businessService" method="doBefore"/>
  111. <aop:after pointcut-ref="businessService" method="doAfter"/>
  112. <aop:around pointcut-ref="businessService" method="doAround"/>
  113. <aop:after-throwing pointcut-ref="businessService" method="doThrowing" throwing="ex"/>
  114. </aop:aspect>
  115. </aop:config-->
  116. <aop:config>
  117. <aop:pointcut id="txPointcut"
  118. expression="execution(* (com.xt.jygl.common.service.JyglBaseService+).*(..))" />
  119. <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />
  120. </aop:config>
  121. <bean id="sessionFactory"
  122. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  123. <property name="dataSource" ref="dataSource" />
  124. <property name="hibernateProperties">
  125. <props>
  126. <prop key="hibernate.dialect">${hibernate.dialect}</prop>
  127. <prop key="hibernate.show_sql">false</prop>
  128. <prop key="hibernate.format_sql">true</prop>
  129. <prop key="hibernate.jdbc.fetch_size">50</prop>
  130. <prop key="hibernate.jdbc.batch_size">25</prop>
  131. <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
  132. </props>
  133. </property>
  134. </bean>
  135. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  136. <property name="dataSource" ref="dataSource" />
  137. </bean>
  138. <bean id="webConfiguration" class="com.xtframe.web.support.XtWebConfiguration">
  139. <property name="entityManagerFactory" ref="entityManagerFactory" />
  140. <property name="entityManager">
  141. <bean class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
  142. <property name="persistenceUnitName" value="persistence_unit_1" />
  143. </bean>
  144. </property>
  145. </bean>
  146. <!-- 调度器 -->
  147. <bean name="schedulerFactoryBean"
  148. class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  149. <!-- 通过applicationContextSchedulerContextKey属性配置spring上下文 -->
  150. <property name="applicationContextSchedulerContextKey">
  151. <value>applicationContext</value>
  152. </property>
  153. </bean>
  154. <bean id="webContext" class="com.xtframe.web.support.XtWebContextFactoryBean">
  155. <property name="webConfiguration" ref="webConfiguration" />
  156. <property name="scheduler" ref="schedulerFactoryBean" />
  157. </bean>
  158. <bean id="securityContext" factory-bean="webContext"
  159. factory-method="getSecurityContext" />
  160. <bean id="bizLogRecorder" factory-bean="securityContext"
  161. factory-method="getBizLogRecorder" />
  162. <bean id="queryService" factory-bean="securityContext"
  163. factory-method="getQueryService" />
  164. <bean id="menuService" factory-bean="securityContext"
  165. factory-method="getMenuService" />
  166. <bean id="securityMgr" factory-bean="securityContext"
  167. factory-method="getSecurityMgr" />
  168. <!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
  169. <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  170. destroy-method="close" lazy-init="false">
  171. Connection Info
  172. <property name="driverClassName" value="${jdbc.driver}" />
  173. <property name="url" value="${jdbc.url}" />
  174. <property name="username" value="${jdbc.username}" />
  175. <property name="password" value="${jdbc.password}" />
  176. Connection Pooling Info
  177. <property name="maxIdle" value="${dbcp.maxIdle}" />
  178. <property name="maxActive" value="${dbcp.maxActive}" />
  179. <property name="defaultAutoCommit" value="false" />
  180. <property name="timeBetweenEvictionRunsMillis" value="3600000" />
  181. <property name="minEvictableIdleTimeMillis" value="3600000" />
  182. </bean> -->
  183. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  184. destroy-method="close" lazy-init="false">
  185. <!-- Connection Info -->
  186. <property name="driverClassName" value="${jdbc.driver}" />
  187. <property name="url" value="${jdbc.url}" />
  188. <property name="username" value="${jdbc.username}" />
  189. <property name="password" value="${jdbc.password}" />
  190. <!-- Connection Pooling Info -->
  191. <!-- 连接池启动时的初始值 -->
  192. <property name="initialSize" value="${dbcp.initialSize}" />
  193. <!-- 最大连接数据库连接数,设置为0时,表示没有限制 -->
  194. <property name="maxActive" value="${dbcp.maxActive}" />
  195. <!-- 最大等待连接中的数量,设置为0时,表示没有限制 -->
  196. <property name="maxIdle" value="${dbcp.maxIdle}" />
  197. <!-- 最小等待连接中的数量,设置为0时,表示没有限制 -->
  198. <property name="minIdle" value="${dbcp.minIdle}" />
  199. <!-- sql验证 主要是防止重启数据库时,去先前已有的连接时报错,这个是在需要连接验证时用到 -->
  200. <property name="validationQuery" value="SELECT 1 FROM DUAL " />
  201. <!-- 取出连接时进行有效性验证 默认是true,设置为false,提高性能 -->
  202. <property name="testOnBorrow" value="false" />
  203. <!-- 最大等待时间 -->
  204. <property name="maxWait" value="60000" />
  205. <!-- 设置从数据源中返回的连接是否采用自动提交机制,默认值为 true -->
  206. <property name="defaultAutoCommit" value="false" />
  207. <!-- 每30秒运行一次空闲连接回收器,如果当前连接数小于minIdle会去创建 -->
  208. <property name="timeBetweenEvictionRunsMillis" value="300000" />
  209. <!-- 池中的连接空闲30分钟后被回收 -->
  210. <property name="minEvictableIdleTimeMillis" value="1800000" />
  211. </bean>
  212. </beans>