OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.52k stars 1.93k forks source link

Spring can't seem to autowire a FeignClient bean in multi-module project #1917

Closed bandrefilipe closed 1 year ago

bandrefilipe commented 1 year ago

Hi! Spring doesn't seem to register my feign client on its bean factory, thus not being able to inject it into other beans, under this set of project settings:

See this example: https://github.com/bandrefilipe/teste-feign

Whenever I run this sample, I get Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'com.example.feign.Client' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

I have a similar configured project running Spring Boot 2.7.4, Spring Cloud 2021.0.4 and JDK 17 where this exact package/module structure works with FeignClient.

Can someone tell my what I'm doing wrong?

bandrefilipe commented 1 year ago

Fixed! Turns out I mistakenly declared spring cloud dependencies' bill of materials inside subprojects configuration section in my build.gradle, and not inside the allprojects section, as I should.

This fixed:

allprojects {
    // ...
    dependencyManagement {
        imports {
            mavenBom("org.springframework.cloud:spring-cloud-dependencies:2022.0.0")
        }
    }
    // ...
}
subprojects {
    // ...
    dependencyManagement {
        imports {
            mavenBom(SpringBootPlugin.BOM_COORDINATES)
        }
    }
    // ...
}