aop:advisor

package com.crm.web.aop;

import java.lang.reflect.Method;

import org.springframework.aop.ThrowsAdvice;

public class throwErrro implements ThrowsAdvice {
 public void afterThrowing(Method method, Object[] args, Object target,
   Throwable subclass) throws Throwable {
  
  System.out.println("执行"+target.getClass().getName()+"的"+method.getName()+"方法抛出"+subclass.getClass().getName());
 }
}

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
 http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-2.0.xsd ">


 <bean id="myTransaction"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionfactory"></property>
 </bean>

 <bean id="LogAdvice" class="com.crm.web.aop.throwErrro"></bean>

 <tx:advice id="txAdvice" transaction-manager="myTransaction">
  <tx:attributes>
   <tx:method name="add*" propagation="REQUIRED" />
   <tx:method name="del*" propagation="REQUIRED" />
   <tx:method name="update*" propagation="REQUIRED" />
   <tx:method name="do*" propagation="REQUIRED" />
   <tx:method name="*" propagation="SUPPORTS"/>
  </tx:attributes>
 </tx:advice>

 <!--注意了代理方式-->
 <aop:config proxy-target-class="true">
  <aop:pointcut id="put"
   expression="execution(* com.crm.web.biz.impl.*.*(..))" />

扫描二维码关注公众号,回复: 821422 查看本文章

  <aop:advisor advice-ref="txAdvice" pointcut-ref="put" />

  <aop:advisor advice-ref="LogAdvice" pointcut-ref="put" />

 </aop:config>

</beans>

猜你喜欢

转载自j2ee2009.iteye.com/blog/1072289