Quartz 中调用Feign 报错
来源:7-1 使用Feign实现远程HTTP调用

HZIHUI
2020-04-11
目哥,我在Quartz中添加了已个任务,任务执行类中调用了feign然后报错了。有什么办法可以解决吗?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.oauth2ClientContext': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is 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.
feign 客户端代码
@FeignClient(contextId = "activityService", value = ServiceNameConstants.COMMUNIRY_SERVICE)
@RequestMapping("/activity")
public interface ActivityService {
@GetMapping("/{id}")
R<CommunityActivity> getInfo(@PathVariable("id") String id);
}
使用了feign 拦截器
@Slf4j
public class FeignInnerClientInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
requestTemplate.header("FORM","inner");
}
}
任务执行器代码
public class QuartzTest implements Job {
@Autowired
private ActivityService activityService;
@Override
@SneakyThrows
public void execute(JobExecutionContext jobExecutionContext) {
CommunityActivity activity = activityService.getInfo("1").getData();
log.info("activity: {}",activity.toString());
}
}
写回答
2回答
-
大目
2020-04-11
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.oauth2ClientContext': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception
亲,你贴的代码貌似和这个异常对不上哈…
00 -
大目
2020-04-11
可以贴下你完整的代码哈。单靠这行代码我也定位不了哈。
032020-04-12
相似问题