探讨AOP的两种实现方式

基于 AOP 的 XML架构

<aop:config>
   <aop:aspect id="myAspect" ref="aBean">//定义一个切面
       <aop:pointcut id="businessService" //定义了一个切入点
        expression="execution(* com.tutorialspoint.Student.getName(..))"/>
        //切入点将与指定类的指定方法相匹配
       <aop:before pointcut-ref="businessService" //定义通知、关联切入点
         method="doRequiredTask"/>
       ...
   </aop:aspect>
</aop:config>

<bean id="aBean" class="..."> //将被配置和依赖注入
...
</bean> 

基于 AOP 的 @AspectJ

<aop:aspectj-autoproxy/> //@AspectJ 支持是可用的。
@Aspect
public class AspectModule {
}

@Pointcut("execution(* com.xyz.myapp.service.*.*(..))") 
private void businessService() {}  // id=方法名

@Before("businessService()")
public void doBeforeTask(){
 ...
}

@Before("execution(* com.xyz.myapp.service.*.*(..))")//直接内联切入点
public doBeforeTask(){
 ...
}

dependency:aspectjweaver

原文地址:https://www.cnblogs.com/mo-jian-ming/p/13273552.html