在使用OpenFeign调用时,如果目标服务只有一个,而我们想将调用接口分成两个service类,有时间会报这个错:
FeignClientSpecification’ could not be registered. A bean with that name has already been defined and overriding is disabled

这个是因为我们在两个service类上面添加注解时:@FeignClient 时,里面的name值设置为同一个了,但是又因为请求的日标服务是同一个,name必须一样,这个时间该怎么办呢? 可以使用另一个属性来标识不同的service,就是:contextId,如下所示:

@FeignClient(contextId = "friend", name = "${vm.config.scene-server-name}", path = "friend")
public interface FriendFeignService {
}

@FeignClient(contextId = "user", name = "${vm.config.scene-server-name}", path = "user")
public interface UserFeignService {
}

这样就可以标识为两个不同的service了,注入到spring 的bean也不会重复了

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐