Spring AOP配置报错:Per-clause not recognized及aspectj依赖版本问题
问题原因及解决方案
报错原因
- @Aspect注解参数误用:
@Aspect("pmAspect")中的参数不符合AspectJ的per-clause语法规范,Spring AOP默认无需指定自定义字符串作为参数,这种写法会被识别为无效的per-clause,导致切面解析失败。 - 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
相关产品推荐
相关产品推荐

