You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

Adding a Second Destination to Your SAP Cloud Platform Java App

Hi Sankeerth, great question! Adding a second destination to your app just requires updating the existing destinations environment variable with an additional entry in the JSON array. Here are two reliable ways to do this:

Method 1: Update the Environment Variable Directly

Since cf set-env overwrites the existing value, you need to include both your original destination and the new one in the command. Use a valid JSON array (note the comma separating the two destination objects):

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

Pro tip: While you can write the JSON on a single line, formatting it with line breaks makes it easier to read and avoid syntax errors.

Method 2: Safely Modify Existing Configuration

If you want to avoid retyping your original destination details, follow these steps:

  1. First, retrieve your current destinations configuration:
    cf env firstapp
    
    Look for the destinations entry under User-Provided Environment Variables and copy the entire JSON array.
  2. Add your second destination object to the array (make sure to add a comma after the first object):
    [
      {
        "name": "ErpQueryEndpoint",
        "url": "https://URL",
        "username": "USER",
        "password": "PASSWORD"
      },
      {
        "name": "SecondDestination",
        "url": "https://SECOND_DESTINATION_URL",
        "username": "SECOND_USER",
        "password": "SECOND_PASSWORD"
      }
    ]
    
  3. Update the environment variable with the modified JSON:
    cf set-env firstapp destinations 'PASTE_YOUR_MODIFIED_JSON_HERE'
    

Final Step: Apply the Changes

After updating the environment variable, you need to restage your app for the changes to take effect:

cf restage firstapp

Restaging ensures the app picks up the new environment variables during the build process, which is more reliable than a simple restart for Java apps.

内容的提问来源于stack exchange,提问作者Sankeerth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:21:02