'The bean 'exampleService.FeignClientSpecification' could not be registered. Bean already defined and overriding is disabled
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?
Solution 1:[1]
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 {
}
Solution 2:[2]
This can also happen if you have more than 1 @FeignClients defined with the same name: Link
Giving unique names in my clients fixed it for me
Solution 3:[3]
I had this same problem.
For me it was a maven issue, it seemed like 2 copies of the same library were being used (not because of a real problem but because maven had "got confused". I had been maven installing local builds of a library).
I resolved the problem by deleting my C:\Users{user}.m2\repository and then reimporting the project
Solution 4:[4]
Try deleting FeignClient interface(ExampleClient) from your test package and run the test case and I hope it should work now.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Grim |
Solution 3 | Richard Tingle |
Solution 4 | Rajesh |