Issue
I am starting my microservice and throw this error:
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'soa-user-service.FeignClientSpecification', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
I know change the overriding config may fix this problem. But I am wondering is there any other way to avoid this problem. change the overriding config just avoid the problem, may not solve the problem security.I need to define multi foreign client in one microservice, because I want to category my service api in multi controller, my controller like this:
@RequestMapping(value="/soa/login")
@FeignClient(name = "soa-user-service")
public interface ILoginController {
}
@RequestMapping(value="/soa/login")
@FeignClient(name = "soa-user-service")
public interface IUserController {
}
if I put all api in one controller,this controller api is so long and unreadable. Here is my question: It has better way to avoid conflict in multi controller in one microservice?
PS:
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
Solution
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)
In order to work, your example needs to change in the following way:
@RequestMapping(value="/soa/login")
@FeignClient(name = "soa-login-service")
public interface ILoginController {
}
@RequestMapping(value="/soa/login")
@FeignClient(name = "soa-user-service")
public interface IUserController {
}
Answered By - Miguel Ruiz