读书人

Flex系列-5-宣言式事务

发布时间: 2012-07-19 16:02:19 作者: rapoo

Flex系列--5--声明式事务

?

注意事项:
以下内容基于“Flex4系列整合iBATIS 2.3

  • 配置 advice
    增加命名空间?

    ?

    <beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:flex="http://www.springframework.org/schema/flex"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:tx="http://www.springframework.org/schema/tx"       xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd       http://www.springframework.org/schema/flex       http://www.springframework.org/schema/flex/spring-flex-1.0.xsd       http://www.springframework.org/schema/context       http://www.springframework.org/schema/context/spring-context-3.0.xsd       http://www.springframework.org/schema/tx       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    追加 advice

    <tx:advice id="txAdvice" transaction-manager="txManager">  <tx:attributes>    <tx:method name="get*" read-only="true"/>    <tx:method name="insert*"/>    <tx:method name="update*"/>    <tx:method name="delete*"/>  </tx:attributes></tx:advice>
  • 配置切入点
    增加命名空间?

    ?

    <beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:flex="http://www.springframework.org/schema/flex"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:aop="http://www.springframework.org/schema/aop"       xmlns:tx="http://www.springframework.org/schema/tx"       xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd       http://www.springframework.org/schema/flex       http://www.springframework.org/schema/flex/spring-flex-1.0.xsd       http://www.springframework.org/schema/context       http://www.springframework.org/schema/context/spring-context-3.0.xsd       http://www.springframework.org/schema/aop       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd       http://www.springframework.org/schema/tx       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    追加切入点配置

    <aop:config>  <aop:pointcut id="serviceOperation" expression="execution(* *..*Service.*(..))"/>  <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/></aop:config>

    [注:]加粗部分为 AspectJ 切入点表达式,我会在本系列教程之后详细介绍。

  • 上面的配置实际上做了什么?
    它们被用于围绕 Service 对象创建相应的事务代理,此代理会用 advice 配置。这样当 Service 中的方法在代理上执行时相应的事务也就启动了。
  • 运行 sampleApp

  • 读书人网 >flex

    热点推荐