开发者社区> 问答> 正文

如何为同一Feign客户端界面的不同配置文件切换2个注释

如何为同一Feign客户端界面的不同配置文件切换2个注释?

与负载均衡器URL一起使用时,我使用Feign Client Interface具有以下代码。我称之为Non-Eureka,以供参考:

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

}

另一方面,在使用Eureka和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);

}

现在,我的要求是通过类似Spring Profile的方式来控制它们,以便如果配置文件名称=“ Eureka”,则Eureka注释处于活动状态,而Non-Eureka处于活动状态。

我必须以某种方式在单个接口名称中执行此操作,因为我使用它的方式如下:

private final DepositFeignClient depositFeignClient;
//other code
DepositResponse depResponse =
                    depositFeignClient.getDepositDetails(accountNumber);
//other code

请让我知道是否以某种方式使用@Profile, @ConditionalOnProperty或其他任何方式可以帮助解决我的目的。我正在使用Spring-boot 2.x和Java 8

编辑 在Eureka情况下,我使用path和value属性,在非Eureka情况下,我使用名称和url属性,请注意,这就是问题所在。

问题来源:Stack Overflow

展开
收起
montos 2020-03-24 12:39:04 463 0
1 条回答
写回答
取消 提交回答
  • 您应该尝试创建2个application-{profileName}.properites文件,根据需要设置参数,然后在该配置文件处于活动状态时运行。

    本文的第8节也可能对您有用:https : //www.baeldung.com/spring-profiles

    回答来源:Stack Overflow

    2020-03-24 12:39:24
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多