dupengyue
2017-03-06 43a6ba283eff3e640e22bbf354d9572dfc7f954a
VisitFace/face_discern/src/main/resources/spring-context.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
@@ -44,138 +44,6 @@
      <property name="basePackage" value="cn.com.basic.face.discern.baseapi"/>
   </bean>
         
   <!-- 配置事务管理器:AOP中切面类 -->
   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="logRouterDataSource"/>
   </bean>
   <!-- ①配置事务切面 -->
   <aop:config>
      <!-- 声明切入点表达式 -->
      <aop:pointcut expression="execution(* *..*Service.*(..))" id="txPointcut"/>
      <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" order="50"/>
   </aop:config>
   
   <!-- ②配置事务通知 -->
   <!-- 基于注解的声明式事务:@Transactional -->
   <!-- <tx:annotation-driven/> -->
   <!-- 基于XML的声明式事务:
      transaction-manager="transactionManager" 默认配置。可以省略。
    -->
   <tx:advice id="txAdvice" transaction-manager="transactionManager">
      <tx:attributes>
         <!--  isolation="DEFAULT" : 使用数据库默认事务隔离级别:MySQL 4 ; Oracle 2  -->
         <!-- 增,删,改操作都需要增加事务,而且,具体情况使用不同隔离级别  propagation="REQUIRES_NEW"-->
         <tx:method name="save*" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
         <tx:method name="update*" rollback-for="java.lang.Exception" propagation="REQUIRED" />
         <tx:method name="delete*" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
         <tx:method name="regist*" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
         <tx:method name="batch*" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
         <tx:method name="dispatcher*" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
         <tx:method name="create*" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
         <!-- 查询数据一般设置read-only="true",可以提高系统性能 -->
         <tx:method name="get*" read-only="true"/>
         <tx:method name="query*" read-only="true"/>
         <tx:method name="login*" read-only="true"/>
         <tx:method name="servletPathExists" read-only="true"/>
         <tx:method name="existsUserName" read-only="true"/>
         <!-- <tx:method name="*" read-only="true"/> -->
      </tx:attributes>
   </tx:advice>
   <!-- 日志切面对象 -->
   <bean id="logRecorder" class="com.survey.log.aspect.LogRecorder">
      <!-- 不需要手动注入logService对象,采用@Autowired -->
   </bean>
   <!-- 日志切面配置 -->
   <aop:config >
      <!-- 声明切入点表达式 -->
      <aop:pointcut expression="((execution(* *..*Service.save*(..)) or
                           execution(* *..*Service.update*(..)) or
                           execution(* *..*Service.delete*(..)) or
                           execution(* *..*Service.regist*(..)) or
                           execution(* *..*Service.batch*(..)) or
                           execution(* *..*Service.dispatcher*(..))))
                           and (!bean(logServiceImpl))" id="logPointcut"/>
      <!-- 声明切面类的通知方法 -->
      <aop:aspect id="logAspect" ref="logRecorder" order="10">
         <aop:around method="logRecord" pointcut-ref="logPointcut"/>
      </aop:aspect>
   </aop:config>
   <!-- 声明Spring监听器 -->
   <bean id="logCreateTableListener" class="com.survey.log.listener.LogCreateTableListener"></bean>
<!--
   定义任务的详细Bean
   <bean id="jobDetailBean" class="org.springframework.scheduling.quartz.JobDetailBean">
      <property name="jobClass" value="com.survey.log.quartz.AutoCreateTableJobBean"/>
      给任务bean注入属性
      <property name="jobDataMap">
         <map>
            <entry key="logService" value-ref="logServiceImpl"/>
         </map>
      </property>
   </bean>
   设置触发器
   <bean id="triggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
      <property name="jobDetail" ref="jobDetailBean"/>
      0 0 0 15 * ?
      <property name="cronExpression" value="*/10 * * * * ?"/>
      <property name="cronExpression" value="0 0 0 15 * ?"/>
   </bean>
   声明调度工厂Bean
   <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
      <property name="triggers">
         <list>
            <ref bean="triggerBean"/>
         </list>
      </property>
   </bean>
       -->
   <!--
   配置缓存抽象:
   <bean id="methodKeyGenerator" class="com.survey.ehcache.MethodKeyGenerator"></bean>
   <bean id="ehCacheManagerFactoryBean" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
      <property name="configLocation" value="classpath:ehcache.xml"></property>
   </bean>
   <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
      <property name="cacheManager" ref="ehCacheManagerFactoryBean"/>
   </bean> -->
   <!--
      配置缓存通知:
      id : 通知id
      cache-manager : 设置缓存管理器(切面类)将数据往缓存中方法,以及从缓存中获取,清理缓存;
      key-generator : 用于声明缓存Map集合key
    -->
   <cache:advice id="cacheAdviceId" cache-manager="cacheManager" key-generator="methodKeyGenerator">
      <!--
         cache : 设置缓存方法的返回结果,存放到哪一个名称的缓存区中;对应ehcache.xml文件中的<cache>标签的name属性值
       -->
      <cache:caching cache="surveyCache">
         <!-- 配置哪些方法的返回结果需要往缓存中存储 -->
         <!-- 需要考虑,那么方法的返回结果适合使用二级缓存 -->
         <cache:cacheable method="servletPathExists"/>
      </cache:caching>
   </cache:advice>
   <aop:config>
      <!-- 匹配哪些方法需要参与二级缓存操作 -->
      <aop:pointcut expression="execution(* *..*Service.get*(..)) or
                           execution(* *..*Service.query*(..)) or
                           execution(* *..*Service.servletPathExists(..))" id="ehCachePointcut"/>
      <aop:advisor advice-ref="cacheAdviceId" pointcut-ref="ehCachePointcut"/>
   </aop:config>
</beans>