gpt4 book ai didi

spring-boot - Feign 客户端子域 : ambiguous mapping

转载 作者:行者123 更新时间:2023-12-04 01:46:11 24 4
gpt4 key购买 nike

我正在使用 Spring Boot 2.0.3.RELEASE 和 openFeign:

        <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

我在我的项目中声明了两个假客户:

@FeignClient(name = "appleReceiptSandboxFeignClient",
url = "https://sandbox.itunes.apple.com",
configuration = Conf.class)
@RequestMapping(produces = "application/json", consumes = "application/json")
public interface AppleReceiptSandboxFeignClient {

@RequestMapping(value = "/verifyReceipt", method = RequestMethod.POST)
AppleReceiptResponseDTO sandboxVerifyReceipt(@RequestBody AppleReceiptRequestDTO dto);

}
@FeignClient(name = "appleReceiptFeignClient",
url = "https://buy.itunes.apple.com")
@RequestMapping(produces = "application/json", consumes = "application/json")
public interface AppleReceiptFeignClient {

@RequestMapping(value = "/verifyReceipt", method = RequestMethod.POST)
AppleReceiptResponseDTO productionVerifyReceipt(@RequestBody AppleReceiptRequestDTO dto);

}

我的问题是,即使base urls和name不一样,似乎feign客户端也被认为是冲突的。

java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'com.myproject.central.client.AppleReceiptSandboxFeignClient' method 
public abstract com.myproject.central.client.dto.AppleReceiptResponseDTO com.myproject.central.client.AppleReceiptSandboxFeignClient.sandboxVerifyReceipt(com.myproject.central.client.dto.AppleReceiptRequestDTO)
to {[/verifyReceipt],methods=[POST],consumes=[application/json],produces=[application/json]}: There is already 'com.myproject.central.client.AppleReceiptFeignClient' bean method
public abstract com.myproject.central.client.dto.AppleReceiptResponseDTO com.myproject.central.client.AppleReceiptFeignClient.productionVerifyReceipt(com.myproject.central.client.dto.AppleReceiptRequestDTO) mapped.

即使此映射错误是意料之外的,我也愿意解决问题。

我显然不能在同一个 feign 客户端中声明两个端点,因为子域不同,或者我错过了什么?

我的问题是:仅使用 feign 客户端最简单的解决方法(如果有的话)是什么?

最佳答案

当你用@RequestMapping注解一个接口(interface)或类时,即使你有一个@FeignClient注解,Spring也会注册一个处理程序。您可以通过从界面中删除注释并仅在方法上使用它来解决此问题。

@FeignClient(name = "appleReceiptSandboxFeignClient",
url = "https://sandbox.itunes.apple.com",
configuration = Conf.class)
public interface AppleReceiptSandboxFeignClient {

@RequestMapping(value = "/verifyReceipt", method = RequestMethod.POST, produces = "application/json", consumes = "application/json", pro)
AppleReceiptResponseDTO sandboxVerifyReceipt(@RequestBody AppleReceiptRequestDTO dto);

}
@FeignClient(name = "appleReceiptFeignClient",
url = "https://buy.itunes.apple.com")
public interface AppleReceiptFeignClient {

@RequestMapping(value = "/verifyReceipt", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
AppleReceiptResponseDTO productionVerifyReceipt(@RequestBody AppleReceiptRequestDTO dto);

}

关于spring-boot - Feign 客户端子域 : ambiguous mapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55196238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com