2017-08-16 16 views
0

我有一个使用Google App Engine for Java的已部署应用程序。如何将远程数据存储(从生产)用于本地开发服务器?如何使用Java从本地开发服务器访问生产数据存储?

我的问题与that one非常相似,只是我问的是Java而不是Python。

+0

请告诉我你的使用情况?您可以将应用程序解析为其他项目标识,并使用数据存储管理员将数据存储从一个项目克隆到新项目。顺便说一下,我很确定你链接的问题中的'bulkloader.py'解决方案只是一个可以运行的独立脚本。不要紧,你的项目是在Java中。 – Alex

回答

1

本地程序可以通过service-account authonticated。

Herehere是关于如何在java程序中使用服务帐户的文档。

使用环境变量:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json 

或供应JSON文件的凭据:

import com.google.auth.oauth2.GoogleCredentials; 
import com.google.cloud.datastore.Datastore; 
import com.google.cloud.datastore.DatastoreOptions; 
import com.google.cloud.datastore.Entity; 
import com.google.cloud.datastore.Key; 
import com.google.cloud.datastore.KeyFactory; 

DatastoreOptions options = DatastoreOptions.newBuilder() 
    .setProjectId(PROJECT_ID) 
    .setCredentials(GoogleCredentials.fromStream(
    new FileInputStream(PATH_TO_JSON_KEY))).build(); 
Datastore datastore = options.getService(); 
KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND); 
Key key = keyFactory.newKey(keyName); 
Entity entity = datastore.get(key); 
相关问题