2015-11-20 33 views
0

System.getenv()返回帶有VCAP_SERVICES:「******」的json。我的雲代工Java spring-boot應用綁定到三個服務。如果我在CLI中給出'cf env app_name',它將正確返回所有綁定的服務。此外VCAP_APPLICATION和返回的JSON中的其他字段都很好,除了這個。System.getenv()返回VCAP_SERVICES:「******」

小背景: 我需要獲取綁定到我的應用的所有服務的服務名稱,標籤和計劃。我是新的雲代工和春季啓動,所以不知道如何在我的代碼中使用Spring雲連接器。

回答

0

環境變量VCAP_SERVICES中的值將是您需要解析的JSON字符串,它將爲您提供一個描述所有綁定服務的對象,其中包括名稱,標籤和計劃等數據。如果您的Google「vcap服務」或「雲代工環境變量」的第一個結果是this doc,並且它有一個section on VCAP_SERVICES。下面是他們提供的這是什麼JSON對象看起來像(後解析)的例子:

{ 
    "elephantsql": [ 
    { 
     "name": "elephantsql-c6c60", 
     "label": "elephantsql", 
     "tags": [ 
     "postgres", 
     "postgresql", 
     "relational" 
     ], 
     "plan": "turtle", 
     "credentials": { 
     "uri": "postgres://seilbmbd:[email protected]:5432/seilbmbd" 
     } 
    } 
    ], 
    "sendgrid": [ 
    { 
     "name": "mysendgrid", 
     "label": "sendgrid", 
     "tags": [ 
     "smtp" 
     ], 
     "plan": "free", 
     "credentials": { 
     "hostname": "smtp.sendgrid.net", 
     "username": "QvsXMbJ3rK", 
     "password": "HCHMOYluTv" 
     } 
    } 
    ] 
}