context.xml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:context="http://www.springframework.org/schema/context"
  3. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:cache="http://www.springframework.org/schema/cache" xmlns:util="http://www.springframework.org/schema/util"
  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/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
  9. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
  10. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  11. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
  12. http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">
  13. <bean id="propertyConfigurer"
  14. class="com.uas.platform.b2c.core.support.EncryptablePropertyPlaceholderConfigurer">
  15. <property name="locations">
  16. <list>
  17. <value>classpath*:${profile}/*.properties</value>
  18. </list>
  19. </property>
  20. </bean>
  21. <!--<context:property-placeholder location="classpath*:${profile}/*.properties" />-->
  22. <!-- 系统运行参数注入 -->
  23. <util:properties id="sys"
  24. location="classpath:${profile}/sys.properties" />
  25. <!-- 消息参数 -->
  26. <util:properties id="message"
  27. location="classpath:${profile}/message.properties" />
  28. <!-- 注册spring上下文对象 -->
  29. <bean class="com.uas.platform.b2c.core.support.ApplicationContextRegister" />
  30. <!-- 容器启动完成之后执行 -->
  31. <bean class="com.uas.platform.b2c.core.support.ContextRefreshedProcessor" />
  32. <context:component-scan base-package="com.uas.platform" />
  33. <context:annotation-config />
  34. <!-- 开启@AspectJ AOP代理 -->
  35. <aop:aspectj-autoproxy />
  36. <!-- 任务调度器 -->
  37. <task:scheduler id="scheduler" pool-size="10" />
  38. <!-- 任务执行器 -->
  39. <task:executor id="executor" pool-size="10" />
  40. <!--开启注解调度支持 @Async @Scheduled -->
  41. <task:annotation-driven executor="executor"
  42. scheduler="scheduler" proxy-target-class="true" />
  43. <!-- 国际化的消息资源文件(本系统中主要用于显示/错误消息定制) -->
  44. <bean id="messageSource"
  45. class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
  46. <property name="basenames">
  47. <list>
  48. <value>classpath:spring/messages</value>
  49. </list>
  50. </property>
  51. <property name="useCodeAsDefaultMessage" value="false" />
  52. <property name="defaultEncoding" value="UTF-8" />
  53. <property name="cacheSeconds" value="60" />
  54. </bean>
  55. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  56. destroy-method="close">
  57. <property name="driverClassName" value="${jdbc.driverClassName}" />
  58. <property name="url" value="${jdbc.url}" />
  59. <property name="username" value="${jdbc.username}" />
  60. <property name="password" value="${jdbc.password}" />
  61. <!-- 连接初始值,连接池启动时创建的连接数量的初始值 -->
  62. <property name="initialSize" value="${jdbc.initialSize}" />
  63. <!-- 连接池的最大值,同一时间可以从池分配的最多连接数量,0时无限制 -->
  64. <property name="maxActive" value="${jdbc.maxActive}" />
  65. <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 ,0时无限制 -->
  66. <property name="maxIdle" value="${jdbc.maxIdle}" />
  67. <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
  68. <property name="minIdle" value="${jdbc.minIdle}" />
  69. <!-- 是否对已备语句进行池管理(布尔值),是否对PreparedStatement进行缓存 -->
  70. <property name="poolPreparedStatements" value="true" />
  71. <!-- 是否对sql进行自动提交 -->
  72. <property name="defaultAutoCommit" value="true" />
  73. <!-- 回收超时连接 -->
  74. <property name="removeAbandoned" value="true" />
  75. <!-- 连接空闲时校验连接有效性 -->
  76. <property name="testWhileIdle" value="true" />
  77. <!-- 校验连接有效性的sql -->
  78. <property name="validationQuery" value="select 1 from dual" />
  79. <!-- 每过timeBetweenEvictionRunsMillis 时间,就会启动一个线程,校验连接池中闲置时间超过minEvictableIdleTimeMillis的连接对象 -->
  80. <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
  81. <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
  82. </bean>
  83. <!-- hibernate jpa -->
  84. <bean class="org.springframework.orm.jpa.JpaTransactionManager"
  85. id="transactionManager">
  86. <property name="entityManagerFactory" ref="entityManagerFactory" />
  87. </bean>
  88. <tx:annotation-driven transaction-manager="transactionManager" />
  89. <bean id="transactionInterceptor"
  90. class="org.springframework.transaction.interceptor.TransactionInterceptor">
  91. <property name="transactionManager" ref="transactionManager" />
  92. <property name="transactionAttributeSource">
  93. <bean
  94. class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"></bean>
  95. </property>
  96. </bean>
  97. <bean id="transactionAttributeSourceAdvisor"
  98. class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
  99. <property name="transactionInterceptor" ref="transactionInterceptor" />
  100. </bean>
  101. <bean id="entityManagerFactory"
  102. class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  103. <property name="persistenceUnitName" value="persistenceUnit" />
  104. <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"/>
  105. <property name="packagesToScan" value="com.uas.platform" />
  106. <property name="dataSource" ref="dataSource" />
  107. <property name="jpaVendorAdapter">
  108. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
  109. <property name="generateDdl" value="false" />
  110. <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
  111. <property name="showSql" value="false" />
  112. </bean>
  113. </property>
  114. <property name="jpaDialect">
  115. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
  116. </property>
  117. <property name="jpaProperties">
  118. <props>
  119. <prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:spring/ehcache.xml</prop>
  120. <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
  121. </prop>
  122. <prop key="hibernate.cache.use_query_cache">true</prop>
  123. <prop key="hibernate.cache.use_second_level_cache">true</prop>
  124. <prop key="hibernate.generate_statistics">true</prop>
  125. <prop key="hibernate.use_sql_comments">true</prop>
  126. <prop key="hibernate.format_sql">true</prop>
  127. <prop key="hibernate.generate_statistics">true</prop>
  128. <prop key="hibernate.enable_lazy_load_no_trans">true</prop>
  129. </props>
  130. </property>
  131. </bean>
  132. <!-- jdbctemplate -->
  133. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  134. <property name="dataSource" ref="dataSource" />
  135. </bean>
  136. <!-- 使用ehcache对象缓存 -->
  137. <cache:annotation-driven />
  138. <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
  139. <property name="cacheManager" ref="ehcache"></property>
  140. </bean>
  141. <bean id="ehcache"
  142. class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
  143. <property name="configLocation" value="classpath:spring/ehcache.xml"></property>
  144. <property name="shared" value="true"></property>
  145. </bean>
  146. <!-- mail sender -->
  147. <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
  148. <property name="host" value="${email.host}" />
  149. <property name="port" value="${email.port}" />
  150. <property name="javaMailProperties">
  151. <props>
  152. <prop key="mail.smtp.auth">true</prop>
  153. <prop key="mail.smtp.timeout">25000</prop>
  154. <prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
  155. <prop key="mail.smtp.port">465</prop>
  156. <prop key="mail.smtp.socketFactory.port">465</prop>
  157. </props>
  158. </property>
  159. <property name="username" value="${email.username}" />
  160. <property name="password" value="${email.password}" />
  161. </bean>
  162. <bean id="simpleMailMessage" class="org.springframework.mail.SimpleMailMessage">
  163. <property name="from" value="${email.from}" />
  164. </bean>
  165. <bean id="velocityEngine"
  166. class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
  167. <property name="velocityProperties">
  168. <props>
  169. <prop key="resource.loader">class</prop>
  170. <prop key="class.resource.loader.class">
  171. org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
  172. </prop>
  173. <prop key="velocimacro.library"></prop>
  174. </props>
  175. </property>
  176. </bean>
  177. <!-- 文件上传 -->
  178. <bean id="multipartResolver"
  179. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  180. <property name="defaultEncoding" value="utf-8"></property>
  181. </bean>
  182. <!-- 账户中心配置 -->
  183. <bean id="accountConfigurer" class="com.uas.account.web.AccountConfigurer"
  184. init-method="init">
  185. <property name="configPath" value="classpath:${profile}/account.properties" />
  186. </bean>
  187. <import resource="classpath:spring/ehcache.xml"/>
  188. <import resource="classpath:spring/jpa.xml"/>
  189. <import resource="classpath:spring/redis.xml"/>
  190. <import resource="classpath:spring/task.xml"/>
  191. </beans>