我正在尝试使用eclipse在localhost上运行app引擎spring项目。我在控制台中收到以下错误。
Apr 23, 2018 4:01:04 PM com.google.auth.oauth2.ComputeEngineCredentials runningOnComputeEngine
WARNING: Failed to detect whether we are running on Google Compute Engine.
java.net.SocketException: Network is unreachable: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:357)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:104)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
at com.google.auth.oauth2.ComputeEngineCredentials.runningOnComputeEngine(ComputeEngineCredentials.java:191)
at com.google.auth.oauth2.DefaultCredentialsProvider.tryGetComputeCredentials(DefaultCredentialsProvider.java:270)
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentialsUnsynchronized(DefaultCredentialsProvider.java:194)
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:112)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100)
at com.google.cloud.ServiceOptions.defaultCredentials(ServiceOptions.java:298)
at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:272)
at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:102)
at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:35)
...
如何提供在localhost中使用数据存储的凭据? 当我访问数据存储区时,我在控制台上得到以下内容。
2018-04-23 17:22:05.849:WARN:oejs.ServletHandler:qtp152005629-14: org.spring.framework.web.util.NestedServletException: Request processing failed; nested exception is com.google.cloud.datastore.DatastoreException: Unauthenticated.
Caused by:
com.google.cloud.datastore.DatastoreException: Unauthenticated
答案 0 :(得分:2)
Objectify v6使用Datastore SDK for Google Cloud Platform(您可以将其视为GCP&#39; s&#34;通用&#34; SDK)。该SDK会对云服务进行实际的API调用,即使它在本地运行也是如此。如果要对本地数据存储区运行测试/开发,则需要执行以下两项操作之一。
选项一
使用App Engine SDK的数据存储区绑定,而不是使用GCP数据存储区SDK。 Objectify已在v6中承诺使用GCP SDK,但v5使用了App Engine SDK。您可以降级到v5,一切都会#34;只是工作&#34;。
选项二
如果您想继续使用Objectify v6,则需要安装额外的gcloud组件来运行本地数据存储模拟器,并且您需要设置一些环境变量。更多细节here,但简短版本如下:
安装并启动数据存储模拟器:
$ gcloud components install cloud-datastore-emulator
$ gcloud beta emulators datastore start
然后告诉您的应用程序在哪里找到它:
$ (gcloud beta emulators datastore env-init)
或者您可以手动设置相关的环境变量。在运行应用程序的计算机上,按照env-init命令的输出指示设置环境变量和值。例如:
gcloud beta emulators datastore env-init
export DATASTORE_EMULATOR_HOST=localhost:8432
export DATASTORE_PROJECT_ID=my-project-id