2017-08-29 10 views
1

クラウドファウンドリenv変数VCAP_SERVICESからアマゾンRDSデータベースパラメータを取得する単純なJavaアプリケーションがあります。私は次のコードを使用していますが、データベースにアクセスすることはできません。クラウドファウンドリーenv変数を単純なJavaプログラムの中で読むことができません。(春を使用していません)

ライブラリのホームページで提供されているサンプルコードのいずれかを試しています。

クラウドファウンドリアプリケーションログ:

2017-08-28T14:15:44.952-07:00 [APP/PROC/WEB/0] [ERR] WARNING: No suitable service info creator found for service employee-maria-rds. Did you forget to add a ServiceInfoCreator? 
2017-08-28T14:15:44.952-07:00 [APP/PROC/WEB/0] [ERR] Aug 28, 2017 9:15:44 PM org.springframework.cloud.AbstractCloudConnector getServiceInfo 

Javaアプリケーション:コードの上

public class App { 
    public static void main (String args[]) throws InterruptedException, SQLException { 
     CloudFactory cloudFactory = new CloudFactory(); 
     Cloud cloud = cloudFactory.getCloud(); 
     // ServiceInfo has all the information necessary to connect to the underlying service 
     List<ServiceInfo> serviceInfos = cloud.getServiceInfos(); 
     for (ServiceInfo serviceInfo : serviceInfos) { 
      if (serviceInfo instanceof RelationalServiceInfo) { 
       System.out.println(((RelationalServiceInfo) serviceInfo).getJdbcUrl()); 
      } 
}}} 

は何も印刷されません。

クラウドファウンドリーのEnv変数:

{ 
    "staging_env_json": {}, 
    "running_env_json": {}, 
    "system_env_json": { 
    "VCAP_SERVICES": { 
     "mariaDB": [ 
     { 
      "credentials": { 
      "uri": "jdbc:mysql://db1.us-east-1.rds.amazonaws.com:3306/employee", 
      "username": "xxxx", 
      "password": "xxxx", 
      "host": "db1.us-east-1.rds.amazonaws.com", 
      "port": "3306", 
      "database": "employee" 
      }, 
      "syslog_drain_url": null, 
      "volume_mounts": [], 
      "label": "mariaDB", 
      "provider": null, 
      "plan": "Medium-Plan", 
      "name": "employee-maria-rds", 
      "tags": [] 
     }, 
     { 
      "credentials": { 
      "uri": "jdbc:mysql://db2.us-east-1.rds.amazonaws.com:3306/hcm", 
      "username": "xxxx", 
      "password": "xxxx", 
      "host": "db2.us-east-1.rds.amazonaws.com", 
      "port": "3306", 
      "database": "hcm" 
      }, 
      "syslog_drain_url": null, 
      "volume_mounts": [], 
      "label": "mariaDB", 
      "provider": null, 
      "plan": "Small-Plan", 
      "name": "hcm-maria-db", 
      "tags": [] 
     } 
     ] 
    } 
    }, 
    "application_env_json": { 
    "VCAP_APPLICATION": { 
     "cf_api": "https://apps.abc.com", 
     "limits": { 
     "fds": 16384, 
     "mem": 256, 
     "disk": 256 
     }, 
     "application_name": "java-main-application", 
     "application_uris": [], 
     "name": "java-main-application", 
     "space_name": "development", 
     "space_id": "a8844960-4d08-4d80-b589-4ea1473ed0bb", 
     "uris": [], 
     "users": null, 
     "application_id": "004sdf3ef-3d7a-44d6-81d5-a04bwetf62e07", 
     "version": "c31234g56-4f42-4454-b30e-540sdghh684d6", 
     "application_version": "d2ggd656-4f42-4434-b30e-54g2348684d6" 
    } 
    } 
} 

のpom.xml:

<dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-cloudfoundry-connector</artifactId> 
      <version>1.2.4.RELEASE</version> 
     </dependency> 
+1

https://github.com/spring-cloud/spring-cloud-connectors/issues/210での問題による回答 –

答えて

0
String getEnv = System.getenv("VCAP_SERVICES"); 
ObjectMapper objectMapper = new ObjectMapper(); 
Map<String, String> vcapMap = objectMapper.readValue(getEnv, Map.class); 

vcapMap上記店舗VCAPサービスの値と、あなたは値を印刷することができます。

関連する問題