非web请求的feign调用 ,xxl-job的feign调用,报错

2021-11-23 10:22:14 2021-11-23 10:22:14.113 DEBUG [lk-baoding-portal,,,] 6 --- [      Thread-90] com.netflix.hystrix.AbstractCommand      : Error executing HystrixCommand.run(). Proceeding to fallback logic ...
2021-11-23 10:22:14 java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
2021-11-23 10:22:14     at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
2021-11-23 10:22:14     at com.laikang.cloud.starter.common.intercepter.TokenRequestInterceptor.apply(TokenRequestInterceptor.java:38)
2021-11-23 10:22:14     at feign.SynchronousMethodHandler.targetRequest(SynchronousMethodHandler.java:161)
2021-11-23 10:22:14     at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:110)
2021-11-23 10:22:14     at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:89)
2021-11-23 10:22:14     at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:109)
2021-11-23 10:22:14     at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
2021-11-23 10:22:14     at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
2021-11-23 10:22:14     at rx.Observable.unsafeSubscribe(Observable.java:10327)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
2021-11-23 10:22:14     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
2021-11-23 10:22:14     at rx.Observable.subscribe(Observable.java:10423)
2021-11-23 10:22:14     at rx.Observable.subscribe(Observable.java:10390)
2021-11-23 10:22:14     at rx.internal.operators.BlockingOperatorToFuture.toFuture(BlockingOperatorToFuture.java:51)
2021-11-23 10:22:14     at rx.observables.BlockingObservable.toFuture(BlockingObservable.java:410)
2021-11-23 10:22:14     at com.netflix.hystrix.HystrixCommand.queue(HystrixCommand.java:378)
2021-11-23 10:22:14     at com.netflix.hystrix.HystrixCommand.execute(HystrixCommand.java:344)
2021-11-23 10:22:14     at feign.hystrix.HystrixInvocationHandler.invoke(HystrixInvocationHandler.java:170)
2021-11-23 10:22:14     at com.sun.proxy.$Proxy186.consumptionMemberCardNew(Unknown Source)
2021-11-23 10:22:14     at com.laikang.cloud.baoding.server.job.AppointmentStatusJob.lambda$execute$0(AppointmentStatusJob.java:56)
2021-11-23 10:22:14     at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
2021-11-23 10:22:14     at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
2021-11-23 10:22:14     at com.laikang.cloud.baoding.server.job.AppointmentStatusJob.execute(AppointmentStatusJob.java:47)
2021-11-23 10:22:14     at com.xxl.job.core.thread.JobThread$1.call(JobThread.java:134)
2021-11-23 10:22:14     at com.xxl.job.core.thread.JobThread$1.call(JobThread.java:131)
2021-11-23 10:22:14     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2021-11-23 10:22:14     at java.lang.Thread.run(Thread.java:745)

解决办法:模拟web请求就好了

import org.springframework.mock.web.MockHttpServletRequest;

RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));

你可能感兴趣的:(无分类,前端,java,spring,cloud)