22.springAOP切点表达式的抽取以及总结

public class Target implements TargetInterface
{
    @Override
    public void save()
    {
        System.out.println("save running...");
        throw new ClassCastException();
    }

    public void save2()
    {
        System.out.println("save2 running...");
    }
}

    切面:

public class MyAspect
{

    public void afterThrowing()
    {
        System.out.println("异常抛出");
    }

    public void after()
    {
        System.out.println("最终通知");
    }
}

    <!--配置织入:告诉spring 哪些方法(切入点)需要进行哪些增强(前置增强,后置增强...)-->
    <aop:config><!--配置aop-->
        <!--配置切面(切入点+通知)-->
        <aop:aspect id="myAspect" ref="myAspect"><!--声明切面-->
            <aop:pointcut id="save" expression="execution(* aop.*.save(..))"/><!--抽取切点表达式-->
            <aop:after-throwing method="afterThrowing" pointcut-ref="save"></aop:after-throwing>
            <aop:after method="after" pointcut-ref="save"></aop:after>
        </aop:aspect>
    </aop:config>

总结


版权声明:本文为weixin_45974277原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。