How to have 2 annotation toggled for different profile for the same Feign client Interface?
I use a Feign Client Interface which has the following code when used with load balancer url. This I call as Non-Eureka for reference:
@FeignClient(name = "DEPOSIT-FEIGN-CLIENT", url = "${DEPOSIT-DATA-URL}")
public interface DepositFeignClient {
@RequestMapping(method = RequestMethod.GET, value = "/path/to/api/{accountNumber}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
DepositResponse getDepositDetails(@PathVariable(value = "accountNumber") String accountNumber);
}
On the other hand I use the following code when using Eureka and Spring Cloud Gateway:
@FeignClient(value = "ABCD-GATEWAY", path = "${DEPOSIT-EUREKA-APPNAME}")
public interface DepositFeignClient {
@RequestMapping(method = RequestMethod.GET, value = "/path/to/api/{accountNumber}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
DepositResponse getDepositDetails(@PathVariable(value = "accountNumber") String accountNumber);
}
Now my requirement is to control them through something like a Spring Profile, so that if the profile name = "Eureka" the Eureka annotation is active and Non-Eureka is active otherwise.
I have to do it somehow in a single Interface name since I use it like the following:
private final DepositFeignClient depositFeignClient;
//other code
DepositResponse depResponse =
depositFeignClient.getDepositDetails(accountNumber);
//other code
Please let me know if somehow using @Profile, @ConditionalOnProperty
or anything else would help solve my purpose. I am using Spring-boot 2.x and Java 8
Edit
Kindly note in Eureka case I am using path
and value
attributes and in non-Eureka case I am using name and url attributes and that is the problem.