My feign client class is as below along with the Application class.
@FeignClient(name = "ExampleService", configuration = FeignClientConfig.class, url = "http://localhost:8091")
public interface ExampleClient {
@GetMapping(value = "exampleService/exampleDetails/{id}")
public List<ExampleDTO> getExampleDetails(@PathVariable(name = "id") final Long id);
}
@EnableAutoConfiguration
@EnableScheduling
@SpringBootApplication
@EnableFeignClients(basePackages = {"com.package.example"})
@ComponentScan(basePackages = {"com.package"})
public class ExampleApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
In the above code I'm getting the error as given below
APPLICATION FAILED TO START
Description:
The bean 'ExampleService.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding = true
First of all, there's only 1 feign client by that name being defined in the project. Second I tried giving it a context ID just in case there was a bean with the same name being defined somewhere I must've missed.
@FeignClient(contextId = "myExampleService", name="ExampleService", configuration = FeignClientConfig.class, url = "http://localhost:8091")
but again it gave me the same error
The bean 'myExampleService.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.
Third, I also tried by giving the property in application.properties file for overriding the bean
spring.main.allow-bean-definition-overriding = true
but still I'm getting the same error. Any reason why I'm getting this issue even though there is only 1 bean with the name available for Spring's app context?
It might not be the OP's problem since he has only one feign client, but to anyone that got here by googling the same error:
The name attribute of the @FeignClient annotation works as a unique identifier to the client.
If you want to have multiple feign clients within the same Spring context, each needs to have a unique name (or value, as these two attributes are aliases to each other)
For instance:
@RequestMapping(value="/endpoint/path")
@FeignClient(name = "MUST-BE-UNIQUE")
public interface MyClient {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With