3

I have Projects built with Spring-boot, Maven and Kotlin. I want to expose some Services and FeignClients in a maven Project, so others can use them.

For a class with Annotations like @Service that works well. But I need to expose also FeignClients, which are annotated with @FeignClient, but as it looks other Projects are not able to inject those Clients. Do I have to configure something in my pom.xml? Im using spring-cloud-starter-openfeign

Here is some Code. My FeignClient looks like:

...
@FeignClient(name = "MyAPIClient", url = "\${url}", configuration = [MyApiClientConfiguration::class])
interface MyAPIClient {
...

And I try to inject that Client in another Project like this:

...
@Service
class MyService(val myAPIClient: MyAPIClient) {
...

The Error is pretty clear. It says, there is no bean with the name MyAPIClient. So it's not visible or available. "Consider defining a bean of type 'com.mycomp.MyAPIClient' in your configuration."

Do I have to configure something explicitly to expose an OpenFeignClient to other projects in my pom.xml?

Thanks for your help

user3603819
  • 597
  • 1
  • 4
  • 18
  • You seem to be confusing two different tools. Maven is a "software project management and comprehension tool" it is not responsible for autowiring/injecting beans at all. In 99.99% cases maven has no role to play at runtime. You need to configure spring components and package scanning to pick up `FeignClient` annotation. – madteapot Apr 15 '20 at 09:23

1 Answers1

3

It would work automatically if you had the same package structure in both projects. See how the search for feign clients is performed by default.

In other cases, you need to specify basePackages of basePackageClasses attributes of @EnableFeignClients annotation (in the app where you need to inject your feign client). Note that if you do that, then the default behavior (scanning the current package where this annotation is placed) stops working, so you need to specify it manually too in this case.

amseager
  • 5,795
  • 4
  • 24
  • 47