You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

指定argNames时Pointcut无法匹配目标方法的问题求助

指定argNames时Pointcut无法匹配目标方法的问题求助

各位好,我最近在Spring项目里用AOP切面的时候碰到了个头疼的问题,想请大家帮忙看看。

情况是这样的:我有一个接口,它的实现类是Spring管理的Bean:

public interface LeaderboardService {
    List<PlayerRankWithDetails> getTopScores(Long tournamentId, int limit);
}

为了给这个接口的getTopScores方法做增强,我写了一个切面类:

@Aspect
public class LeaderBoardServiceMDCAspect {
    
    @Around(value = "execution(* t.s.l.LeaderboardService.getTopScores(..)) && args(tournamentId, limit)", argNames = "tournamentId,limit")
    public Object addMdcContext(ProceedingJoinPoint joinPoint, Long tournamentId, int limit) throws Throwable {
        // 原本打算在这里把参数放到MDC里做日志上下文
        MDC.put("tournamentId", tournamentId != null ? tournamentId.toString() : "");
        try {
            return joinPoint.proceed();
        } finally {
            MDC.remove("tournamentId");
        }
    }
}

结果发现,一旦我在@Around注解里指定了argNames属性,这个Pointcut就完全匹配不到目标方法了,切面逻辑根本不会执行。但如果我把argNames去掉,切面又能正常工作。我反复核对了参数名称和方法签名,确认是完全对应的,实在搞不懂哪里出问题了,有没有懂AOP的朋友能帮我排查下原因呀?

备注:内容来源于stack exchange,提问作者Sergey Tsypanov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 17:18:08