Spring-cloud-netflix: @FeignClient is now a primary bean and cannot be mocked out anymore

Created on 8 Jun 2016  路  2Comments  路  Source: spring-cloud/spring-cloud-netflix

Since issue #899 a @FeignClient annotated interface will be exposed as a primary bean in spring.
So it cannot be mocked out in tests because then there will be more than one primary bean.
Is it possible to refine the solution of #899 a little bit, so that the primary flag is only set if there is a fallback configured?

duplicate

Most helpful comment

Hello @LutzStrobel ,

i had the same problem and solved it with the following workaround:

  1. Annotate your configuration where @EnableFeignClients is put on with @Profile("!test") (If you have this annotation on a class where other configuration is applied, move it to its own configuration class)
  2. Create a Annotation in your Test which is annotated with @Profile("test") and create your mocks in there.

It isn't beautiful, but it works. Hope it helps

All 2 comments

Hello @LutzStrobel ,

i had the same problem and solved it with the following workaround:

  1. Annotate your configuration where @EnableFeignClients is put on with @Profile("!test") (If you have this annotation on a class where other configuration is applied, move it to its own configuration class)
  2. Create a Annotation in your Test which is annotated with @Profile("test") and create your mocks in there.

It isn't beautiful, but it works. Hope it helps

Duplicate of #1016

Was this page helpful?
0 / 5 - 0 ratings