【sping揭秘】13、Spring AOP一世&二世

Spring AOP一世

 

Spring AOP中的advice

Before advice

这个就是在方法执行之前执行,也就是在对应的joinpoint之前

spring AOP二世

开启aspect注解

如果使用的是spring1.x的话,那么就添加一个bean

    <!-- 开启aop注解 -->
    <bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator">
        <property name="proxyTargetClass" value="true"></property>
    </bean>

如果是spring2.x以上的话,使用xsd的配置方式

<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>

对于@pointcut 这个注解是方法级的,并且如果修饰对象是public的,那么可以在其他的类中的pointcut中直接引用,类似

@pointcut(“package.SystemCommonsAspect.commonPointcut1()。。。

@aspectj形式的advice

@before 

@afterreturning

@afterThrowing

@after

@around

@declareParents

接下来我们依次了解一下

猜你喜欢

转载自www.cnblogs.com/cutter-point/p/8964938.html