konrad-kaminski / spring-kotlin-coroutine

Kotlin coroutine support for Spring.
448 stars 69 forks source link

java.lang.ClassCastException when using @Cacheable with suspend function #34

Open yijunwu opened 5 years ago

yijunwu commented 5 years ago

I'm using Spring 4.3.9 and spring-kotlin-coroutine 0.2.2. What I want to achieve is make spring @Cacheable annotation work with suspend function, but I got the exception below:

java.lang.ClassCastException: org.springframework.kotlin.experimental.coroutine.cache.CoroutineSuspendedException cannot be cast to org.springframework.cache.interceptor.CacheOperationInvoker$ThrowableWrapper
  at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:374)
  at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:327)
  at org.springframework.kotlin.experimental.coroutine.cache.CoroutineCacheInterceptor.executeCoroutine(CoroutineCacheConfiguration.kt:112)
  at org.springframework.kotlin.experimental.coroutine.cache.CoroutineCacheInterceptor.invokeCoroutine(CoroutineCacheConfiguration.kt:100)
  at org.springframework.kotlin.experimental.coroutine.cache.CoroutineCacheInterceptor.invoke(CoroutineCacheConfiguration.kt:83)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
  at com.alibaba.intl.trade.delivery.biz.external.fund.FundServiceGatewayImpl$$EnhancerBySpringCGLIB$$9570d4ab.getNysePaymentFulfilled(<generated>)
  at com.alibaba.intl.trade.delivery.biz.service.impl.DeliveryReadServiceImpl$prefetchShipmentTermAndPayData$paymentFulfilled$1.doResume(DeliveryReadServiceImpl.kt:318)
  at com.alibaba.intl.trade.delivery.biz.service.impl.DeliveryReadServiceImpl$prefetchShipmentTermAndPayData$paymentFulfilled$1.invoke(DeliveryReadServiceImpl.kt)
  at com.alibaba.intl.trade.delivery.biz.service.impl.DeliveryReadServiceImpl$prefetchShipmentTermAndPayData$paymentFulfilled$1.invoke(DeliveryReadServiceImpl.kt:43)
  at com.alibaba.intl.trade.delivery.biz.util.CoroutineUtilKt$async$1.doResume(CoroutineUtil.kt:28)
  at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:54)
  at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:162)
  at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:26)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1147)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
  at java.lang.Thread.run(Thread.java:834)