@EnableFeignClients and @FeignClient fail on Autowiring 'FeignContext' NoSuchBeanException

随声附和 提交于 2019-12-04 02:36:18
Codetector

Seems like there is not anything out there yet about the solution to this stuff...

Here is what I did to solve this: 1. Add this annotation to your test class:

@ImportAutoConfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class})

Try it, if it does not work, you might need the @EnableFeignClients annotation on your main program config

Recommended approach is to slice application configuration, this means you need to remove @EnableFeignClients from SpringBootApplication.

and add dedicated configuration class:

@Configuration
@EnableFeignClients
public class CloudConfiguration {

}

This is required, because all slices annotation (like @WebMvcTest) include default configuration from SpringBootApplication.

Reference:

The only what you must to do:

  • add to your build file feign dependency, for example, for gradle

compile 'org.springframework.cloud:spring-cloud-starter-feign'

  • add @FeignClient to your interface
  • add @EnableFeignClients to any configuration or to class with annotation @SpringBootApplication

I solved this problem just by @EnableAutoConfiguration annotation on my class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!