我正在使用FeignClient调用另一个服务来请求一些资源。通过每x分钟运行一次@Scheduled
注释的方法来调用FeignClient。启动应用程序和正在执行的方法时,将引发以下错误:
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.
我正在使用Kotlin 1.3.31运行Spring Boot 2.1.4。玩弄线程设置似乎没有帮助。
@FeignClient(url = "\${example-service.url}", name = "example-service", configuration = [FeignConfiguration::class])
interface ExampleClient {
@GetMapping("/v1/example/?exampleName={exampleName}")
fun getExampleByNameReponse(@Param("exampleName") exampleName: String): List<ExampleApiResponse>
}
class FeignConfiguration {
@Bean
fun feignContract(): SpringMvcContract = SpringMvcContract()
@Bean
fun feignRequestInterceptor(): RequestInterceptor = FeignRequestInterceptor()
}
我希望计划任务每x周期运行一次,并从FeignClient检索资源而不会引发错误。它必须使用计划任务,因为必须刷新。