Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feign client sub-domain : ambiguous mapping

I'm using Spring Boot 2.0.3.RELEASE and openFeign:

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

I declared two feign clients in my project:

@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);

}

My problem is that even if the base urls and the name are not the same, it seems that the feign clients are considered in collision.

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.

Even if this mapping error is unexpected, I'm opened to workarounds.

I obviously cannot declare the two endpoints in the same feign client because the subdomain differs, or maybe am I missing something ?

My question is: what would be the simplest workaround (if any) using only feign client ?

like image 243
Pierre Mardon Avatar asked Oct 23 '25 09:10

Pierre Mardon


1 Answers

When you annotate an Interface or Class with @RequestMapping Spring will register a handler even if you have a @FeignClient annotation. You can workaround the issue by removing the annotation from the interface and using it only on the method.

@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);

}
like image 59
V. Lovato Avatar answered Oct 26 '25 02:10

V. Lovato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!