1

Good day I am trying to write Feign specific integration test and have specific configuration to enable feign auto configuration it looks like that

@Profile({Profiles.FEIGN_INTEGRATION_TEST, Profiles.PROD, Profiles.DEV, Profiles.STAGE})
@Configuration
@EnableFeignClients
public class FeignEnabler {
}

and in my test (Spock specification)

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWireMock
@ActiveProfiles(Profiles.FEIGN_INTEGRATION_TEST)
class MyServiceSpec extends Specification {

   @Subject
   @Autowired
   MyService myService
}

MyService is using RestClient

@Profile({Profiles.FEIGN_INTEGRATION_TEST, Profiles.PROD, Profiles.DEV, Profiles.STAGE})
@FeignClient(name = "myRestClient", url = "${feign.client.config.myclient.url}")
public interface RestClient

Sadly, running test specification exception appears

Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.myapplication.web.RestClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Workout for that problem would be to add @EnableFeignClients in @SpringBootApplication class, but this way it messes with another tests (in my case DataJpa slice tests) and to avoid it I need to add this line of code

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

as described here https://github.com/spring-projects/spring-boot/issues/7270 for each integration test, not using FeignAutoConfiguration and I really don't want to do that...

artjomka
  • 1,229
  • 3
  • 15
  • 31

0 Answers0