假设客户端子域:模糊映射

问题描述 投票:0回答:1

我正在使用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);

}

我的问题是,即使基本网址和名称不相同,似乎假装客户端也被认为是碰撞。

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客户端声明两个端点,因为子域不同,或者我可能错过了什么?

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

spring-boot spring-cloud-feign
1个回答
1
投票

当您使用@RequestMapping注释接口或类时,即使您有@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);

}
© www.soinside.com 2019 - 2024. All rights reserved.