使用 @FeignClient 的 fallback 时报错:
nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'XXX' method
XXX
to {GET /XX/XX/XX}: There is already 'XXX' bean method
XXX() mapped.
@FeignClient 的属性fallback的值是 当前接口的实现类的类对象
比如:
@Service
@FeignClient(name = "service-name", fallback= TestServiceFallback.class)
@RequestMapping("/test")
public interface TestService{
@GetMapping("/ok")
String ok(){ return "ok"; }
}
@Component
public class TestServiceFallback implements TestService{
public String ok(){return "服务降级"}
}
@FeignClient 注解可以通过类似@Controller 的映射配置,实现声明式的服务调用。
错误原因是,TestServiceFallback方法现实TestService接口会同时实现@RequestMapping的配置导致模糊映射(Ambiguous mapping)