简体   繁体   English

如何在Cloud Foundry中为Java应用程序添加多个目的地?

[英]How to add multiple destinations for a java application in cloud foundry?

I developed a Java application using S4Hana SDK. 我使用S4Hana SDK开发了Java应用程序。 After deploying the application to SAP Cloud platform, I set the destinations as an environment variable with below command. 将应用程序部署到SAP Cloud平台后,我使用以下命令将目标设置为环境变量。

cf set-env firstapp destinations '[{name: "ErpQueryEndpoint", url: "https://URL", username: "USER", password: "PASSWORD"}]'

Now, I would like to add a second destination for the same application. 现在,我想为同一应用程序添加第二个目标。 Can someone please help me? 有人可以帮帮我吗?

Thanks, Sankeerth 谢谢,Sankeerth

You can define multiple destinations in the environment variable. 您可以在环境变量中定义多个目标。 It is a JSON array. 这是一个JSON数组。

cf set-env firstapp destinations '[{name: "ErpQueryEndpoint", url: "https://URL", username: "USER", password: "PASSWORD"},{name: "ErpQueryEndpoint2", url: "https://URL", username: "USER", password: "PASSWORD"}]'

In the execute method in the virtual data model you can define which destination to use: 在虚拟数据模型的execute方法中,可以定义要使用的目标:

BusinessPartnerService service = new DefaultBusinessPartnerService();

final List<BusinessPartner> businessPartners =
        service.getAllBusinessPartner().execute(new ErpConfigContext("ErpQueryEndpoint2"));

However, better than using the environment variables is to use the destination service. 但是,比使用环境变量更好的是使用目标服务。

Step 4 of the SDK tutorials explains how to use this service: https://blogs.sap.com/2017/05/21/step-4-with-sap-s4hana-cloud-sdk-calling-an-odata-service/ SDK教程的第4步说明了如何使用此服务: https : //blogs.sap.com/2017/05/21/step-4-with-sap-s4hana-cloud-sdk-calling-an-odata-service /

With that it is even possible to have destination configurations per tenant. 这样甚至可以为每个租户提供目标配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM