春卷-huachun 2023-07-11 17:31 采纳率: 0%
浏览 9

使用JetCache和AOP出现的异常

Check that an AOP invocation is in progress and that the ExposeInvocationInterceptor is upfront in the interceptor chain
问题描述:在使用jetcache时候发现了如下问题,不知道是因为什么原因导致的,网上大部分解答是说aop顺序问题
详细日志:

Caused by: java.lang.IllegalStateException: No MethodInvocation found: Check that an AOP invocation is in progress and that the ExposeInvocationInterceptor is upfront in the interceptor chain. Specifically, note that advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor! In addition, ExposeInvocationInterceptor and ExposeInvocationInterceptor.currentInvocation() must be invoked from the same thread.
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_162]
[2023-07-11 17:15:12.215]:[ERROR] [JetCacheHeavyIOExecutor0] [] [com.alicp.jetcache.RefreshCache:254]-[refresh error: key=196]
com.alicp.jetcache.CacheException: refresh error
    at com.alicp.jetcache.RefreshCache$RefreshTask.lambda$externalLoad$0(RefreshCache.java:204) ~[jetcache-core-2.6.6.jar!/:?]
    at com.alicp.jetcache.Cache.tryLockAndRun(Cache.java:273) ~[jetcache-core-2.6.6.jar!/:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_162]
    at com.alicp.jetcache.RefreshCache$RefreshTask.externalLoad(RefreshCache.java:209) ~[jetcache-core-2.6.6.jar!/:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_162]
    at com.alicp.jetcache.RefreshCache$RefreshTask.run(RefreshCache.java:249) [jetcache-core-2.6.6.jar!/:?]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.currentInvocation(ExposeInvocationInterceptor.java:73) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_162]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_162]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_162]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_162]
    at com.alicp.jetcache.CacheUtil$1.load(CacheUtil.java:35) ~[jetcache-core-2.6.6.jar!/:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_162]
    at com.alicp.jetcache.RefreshCache$RefreshTask.load(RefreshCache.java:167) ~[jetcache-core-2.6.6.jar!/:?]
Caused by: java.lang.IllegalStateException: No MethodInvocation found: Check that an AOP invocation is in progress and that the ExposeInvocationInterceptor is upfront in the interceptor chain. Specifically, note that advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor! In addition, ExposeInvocationInterceptor and ExposeInvocationInterceptor.currentInvocation() must be invoked from the same thread.
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_162]
    at com.alicp.jetcache.RefreshCache$RefreshTask.lambda$externalLoad$0(RefreshCache.java:200) ~[jetcache-core-2.6.6.jar!/:?]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.getJoinPointMatch(AbstractAspectJAdvice.java:668) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_162]
    ... 10 more
    at org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:44) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.currentInvocation(ExposeInvocationInterceptor.java:73) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:55) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.getJoinPointMatch(AbstractAspectJAdvice.java:668) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_162]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.getJoinPointMatch(AbstractAspectJAdvice.java:668) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
Caused by: java.lang.IllegalStateException: No MethodInvocation found: Check that an AOP invocation is in progress and that the ExposeInvocationInterceptor is upfront in the interceptor chain. Specifically, note that advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor! In addition, ExposeInvocationInterceptor and ExposeInvocationInterceptor.currentInvocation() must be invoked from the same thread.
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.currentInvocation(ExposeInvocationInterceptor.java:73) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at com.alicp.jetcache.anno.method.CacheHandler.invokeOrigin(CacheHandler.java:278) ~[jetcache-anno-2.6.6.jar!/:?]
    at org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:44) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at com.alicp.jetcache.anno.method.CacheHandler.access$000(CacheHandler.java:21) ~[jetcache-anno-2.6.6.jar!/:?]
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:55) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at com.alicp.jetcache.anno.method.CacheHandler$1.load(CacheHandler.java:240) ~[jetcache-anno-2.6.6.jar!/:?]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:44) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at com.alicp.jetcache.anno.method.CacheHandler.invokeOrigin(CacheHandler.java:278) ~[jetcache-anno-2.6.6.jar!/:?]
    at com.alicp.jetcache.anno.method.CacheHandler.access$000(CacheHandler.java:21) ~[jetcache-anno-2.6.6.jar!/:?]
    at com.alicp.jetcache.anno.method.CacheHandler$1.load(CacheHandler.java:240) ~[jetcache-anno-2.6.6.jar!/:?]
    at com.alicp.jetcache.CacheUtil$1.load(CacheUtil.java:35) ~[jetcache-core-2.6.6.jar!/:?]
    at com.alicp.jetcache.RefreshCache$RefreshTask.load(RefreshCache.java:167) ~[jetcache-core-2.6.6.jar!/:?]
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:55) ~[spring-aop-5.2.11.RELEASE.jar!/:5.2.11.RELEASE]
    at com.alicp.jetcache.RefreshCache$RefreshTask.lambda$externalLoad$0(RefreshCache.java:200) ~[jetcache-core-2.6.6.jar!/:?]
    ... 10 more

有没有同学遇到相同的问题,知道是什么原因引起的吗

  • 写回答

1条回答 默认 最新

  • IT论之程序员 2023-07-11 20:50
    关注

    根据报错信息来看,这个问题主要是因为Spring AOP的顺序引起的。
    报错提示:Check that an AOP invocation is in progress and that the ExposeInvocationInterceptor is upfront in the interceptor chain.
    翻译过来就是说,需要确保ExposeInvocationInterceptor这个拦截器在拦截器链的最前面。
    JetCache在刷新缓存时需要使用ExposeInvocationInterceptor拦截器来获取当前的方法调用信息。但是如果这个拦截器不在最前面,就会导致获取不到方法调用信息,从而抛出异常。
    解决方法就是:

    1. 在Spring AOP配置中,确保ExposeInvocationInterceptor这个拦截器在最前面。
    2. 给ExposeInvocationInterceptor设置order值为最高优先级,比如:
      java
      @Bean
      public ExposeInvocationInterceptor exposeInvocationInterceptor() {
      ExposeInvocationInterceptor interceptor = new ExposeInvocationInterceptor();
      interceptor.setOrder(Ordered.HIGHEST_PRECEDENCE);
      return interceptor;
      }
    3. 确保刷新缓存的线程和缓存访问的线程是同一个线程,因为ExposeInvocationInterceptor是基于ThreadLocal工作的。
      所以正确配置Spring AOP的拦截器顺序并确保线程一致性,就可以避免这个问题。
    评论

报告相同问题?

问题事件

  • 创建了问题 7月11日

悬赏问题

  • ¥20 c#使用NPOI向word表格中添加字段导致word有概率警告不可识别
  • ¥15 怎么使用hxe16进制编码器修改视频数据和图片一样!求教程!
  • ¥15 怎么用python模拟光的折射,反射,和全反射
  • ¥15 python打印机打印word和PDF文件出来的是乱码
  • ¥15 求达梦8数据库安装包
  • ¥15 YOLOv8模型网络结构更改后报错
  • ¥15 深度学习中梯度为None
  • ¥15 zynq烧写程序到flash后不运行
  • ¥15 裸板ESD问题的思考与实验
  • ¥15 electron+python