当前位置: 代码迷 >> J2EE >> spring aop配置,该如何解决
  详细解决方案

spring aop配置,该如何解决

热度:322   发布时间:2016-04-17 23:49:26.0
spring aop配置
我在ssh项目中用到了aop配置
但是这一段代码不知道是干什么的
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到 -->
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="count*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="list*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<aop:config proxy-target-class="true">
<aop:advisor
pointcut="(execution(* com.citycard.dao.impl.*.*(..))) OR execution(* com.citycard.dao.impl.*.*(..))"
advice-ref="txAdvice" />
</aop:config>
能大致解释一下这一段是干嘛的吗,网上说这是spring声明式管理事务?这个是什么意思。
propagation="REQUIRED"网上说这个 代表支持当前事务,如果当前没有事务,就新建一个事务这个又是什么意思?太模糊了能说的简单一点吗?
------解决方案--------------------
<tx:advice id="txAdvice" transaction-manager="transactionManager">
*****
</tx:advice>
这个是定义事务管理器(只是定义规则,没有生效),
也就是spring要管理那些方法的事物,以及怎么管理
<aop:config proxy-target-class="true">
***
</aop:config>
这个是spring的面向切面,就是把刚刚的规则用到什么地方。

propagation="REQUIRED"网上说这个 代表支持当前事务,如果当前没有事务,就新建一个事务这个又是什么意思?
意思就是spring在管理事务的时候,如果当前连接中没有开启事务,就开启一个,有的话就用当前的。这句话我觉得已经非常明了了啊
  相关解决方案