FeignClient启动报错

The bean 'item-service.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.

报错原因:

在Spring Boot 2.0.x 中,spring.main.allow-bean-definition-overriding属性默认是 true,注解@FeignClient 没有contextId属性;

在Spring Boot 2.1.x 中,spring.main.allow-bean-definition-overriding属性默认是 false,注解@FeignClient 有contextId属性;

解决方法:

方法1:application.yml添加allow-bean-definition-overriding: true

spring:
  main:
    allow-bean-definition-overriding: true

方法2:为每个Client手动指定不同的contextId,如contextId = "brandFeignClient"

@FeignClient(name = "item-service",contextId = "brandFeignClient")
public interface BrandClient extends BrandApi {
}
©本文为原创文章,著作权归博主所有,转载请联系博主获得授权

发表评论