0
点赞
收藏
分享

微信扫一扫

Spring Cloud Feign--解决服务有多个FeignClient的报错:The bean ‘xxx‘ could not be registered. A bean with tha



简介

        本文介绍feign对一个服务定义多个FeignClient时的报错:The bean 'xxx' could not be registered. A bean with that name has already been defined and overriding is disabled.

问题复现

@FeignClient("user")
public interface TestLongFeignService {
@PostMapping("/user/long")
public ResultWrapper testLong(String param1);
}

@FeignClient("user")
public interface UserFeignService {
@GetMapping("/user/{id}")
public User getUser(@PathVariable("id") Long id);
}

错误日志: 

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

解决方案

方案1:使用contextId属性

@FeignClient(value = "user", contextId = "user1")
public interface TestLongFeignService {
@PostMapping("/user/long")
public ResultWrapper testLong(String param1);
}

@FeignClient(value = "user", contextId = "user2")
public interface UserFeignService {
@GetMapping("/user/{id}")
public User getUser(@PathVariable("id") Long id);
}

方案2:方法都放到同一个类里边

@FeignClient("user")
public interface UserFeignService {
@GetMapping("/user/{id}")
public User getUser(@PathVariable("id") Long id);

@PostMapping("/user/long")
public ResultWrapper testLong(String param1);
}

举报

相关推荐

0 条评论