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

Spring AOP配置报错:Per-clause not recognized及aspectj依赖版本问题

问题原因及解决方案

报错原因

  1. @Aspect注解参数误用:@Aspect("pmAspect")中的参数不符合AspectJ的per-clause语法规范,Spring AOP默认无需指定自定义字符串作为参数,这种写法会被识别为无效的per-clause,导致切面解析失败。
  2. AspectJ依赖版本不一致:aspectjweaver版本为1.8.9,而aspectjrt版本为1.6.1,版本不匹配会引发兼容性问题,干扰AOP代理的创建流程。

解决方案

1. 修正切面类的@Aspect注解

移除@Aspect注解中的无效参数,直接使用@Aspect标记切面类:

@Component
@Aspect 
public class AspectTest {
  @Around(value = "execution(int com.krk.service.ServiceTest.a*(..))")
  public Object around(ProceedingJoinPoint php) throws Throwable {
    System.out.println("before method call");
    Object ob=php.proceed();
    System.out.println("after method call");
    return ob;
  }
}

2. 统一AspectJ依赖版本

将aspectjrt的版本修改为与aspectjweaver一致的1.8.9,确保依赖兼容性:

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.8.9</version>
</dependency>
<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>1.8.9</version>
</dependency>

完成上述修改后,重新启动应用即可解决该报错问题。

内容的提问来源于stack exchange,提问作者KunaRakeshKumar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 00:22:52