AOP和注解的‘继承’
创始人
2024-09-03 08:00:26
0

使用@Inherited注解可以让子类继承父类的注解,但是无法实现对于AOP的继承。需要使用AspectJ的织入方式来解决这个问题。代码示例如下:

首先,在父类上定义一个切入点和切面:

@Pointcut("execution(* com.example.service.*.*(..))")
public void serviceLayerPointcut() {}

@Around("serviceLayerPointcut()")
public Object aroundServiceLayerMethod(ProceedingJoinPoint joinPoint) throws Throwable {
    // your aspect implementation
}

然后,在子类中织入父类的切面:

public class ChildService extends ParentService {

    @Override
    @Around("serviceLayerPointcut()")
    public Object aroundServiceLayerMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        // your aspect implementation for child class
        return super.aroundServiceLayerMethod(joinPoint);
    }
}

这样就可以让子类继承父类的切入点和切面,同时又能够实现对于AOP的继承。

相关内容

热门资讯

透视苹果版!wpk俱乐部有没有... 透视苹果版!wpk俱乐部有没有辅助,aapoker怎么拿好牌(透视)都是存在有挂(AI教程)1、玩家...
透视总结!cloudpoker... 透视总结!cloudpoker外挂,智星德州插件2024最新版,一贯真的有挂(攻略教程)1、智星德州...
透视数据!wepoker免费透... 透视数据!wepoker免费透视脚本,德普之星透视辅助软件激活码(透视)竟然真的是有挂(新版2025...
透视游戏!hardrock作弊... 透视游戏!hardrock作弊,拱趴大菠萝万能挂图解,确实有挂(解密教程);1、这是跨平台的拱趴大菠...
透视脚本!wepoker一直输... 透视脚本!wepoker一直输的号能继续打吗,wpk软件是真的吗(透视)竟然是有挂(曝光教程)进入游...
透视数据!pokemomo辅助... 透视数据!pokemomo辅助软件,智星德州插件,竟然存在有挂(解密教程)1、玩家可以在pokemo...
透视透视!pokemmo辅助器... 透视透视!pokemmo辅助器,hhpoker透视脚本视频(透视)果然是真的有挂(解说技巧);1、进...
透视有挂!pokermaste... 透视有挂!pokermaster脚本,拱趴大菠萝万能挂,原来是真的有挂(详细教程);1、起透看视 拱...
透视好友!扑克之星辅助,德州h... 透视好友!扑克之星辅助,德州hhpoker脚本(透视)确实真的有挂(透牌教程)1、构建自己的德州hh...
透视脚本!pokemmo辅助器... 透视脚本!pokemmo辅助器,佛手在线有挂吗,一直真的是有挂(总结教程);佛手在线有挂吗辅助器中分...