@Component
@Aspect
public class Adervice {
//环绕型通知
@Around("execution(* around*(..))")
public void adviceAround(ProceedingJoinPoint point) throws Throwable{
System.out.println("【====环绕型通知start===】");
point.proceed();//动态执行目标方法
System.out.println("【====环绕型通知end===】");
}
xml配置参照:
<context:component-scan base-package="com.aop.spring.cglibannotation"></context:component-scan>
<!-- 启动@AspectJ支持 -->
<!-- <bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"></bean> -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
xml配置aop
<!-- proxy-target-class="true" 表示是cglib -->
<aop:config proxy-target-class="true">
<aop:pointcut id="aroundPonit" expression="execution(public * around(..)) and args(..)"/>
<aop:aspect ref="adervice">
<aop:around method="adviceAround" pointcut-ref="aroundPonit"/>
<!-- throwing="exc" 要和方法adviceThrowing中传入的参数相同 否则报错-->
<aop:after-throwing method="adviceThrowing" pointcut="execution(public * search(..))" throwing="exc"/>
<aop:before method="beforeAdervice" pointcut="execution(* com.aop.spring.cglibxml.UserDao.beforeUser(..))"/>
<aop:after method="afterAdervice" pointcut="execution(* afterUser(..))"/>
</aop:aspect>
</aop:config>