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