做spring cloud 远程成调用时,多个类标注调用同一个微服务时:
@FeignClient(name = "${remote.feign.edu-authority-boot.name:edu-authority-boot}", path = "/auth", fallbackFactory = AuthProviderFallbackFactory.class) public interface AuthProvider {
@Component @FeignClient(name = "${remote.feign.edu-authority-boot.name:edu-authority-boot}", path = "/menu", fallbackFactory = MenuProviderFallbackFactory.class) public interface MenuProvider {
启动项目时报如下错误:
Description:
The bean '${remote.feign.edu-authority-boot.name:edu-authority-boot}.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
原因: @FeignClient 注解中的name是指定类型的名称,多个类指定同一个名称就会报错,而这里是要进行远程调用的微服务的名称。
解决方式为,在配置文件中加入如下配置:
spring: main: allow-bean-definition-overriding: true