firebase - GAE - 没有为此线程注册 API 环境
问题描述
我有一个使用谷歌应用引擎部署到谷歌云的 spring-boot 应用程序。有一个包含多个实体的数据存储。当我尝试通过我的应用程序检索数据时(应用程序已上传到 appengine,而不是本地),它总是会引发错误 -
出现意外错误(类型=内部服务器错误,状态=500)。没有为此线程注册 API 环境。
我试图让它以这种方式工作:
@Bean
public FirebaseAuth firebaseAuth() throws IOException {
ClassLoader classLoader = this.getClass().getClassLoader();
InputStream
serviceAccount = classLoader.getResourceAsStream("downloaded-key-270620-2a16da8f4062.json");
FirebaseOptions options = (new Builder())
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl(
"https://my-app.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);
return FirebaseAuth.getInstance();
}
private Result<Product> list(boolean wholesale, String startCursorString) {
FetchOptions fetchOptions = Builder.withLimit(10);
if (startCursorString != null && !startCursorString.equals("")) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursorString));
}
Query query = (new Query("Product")).setFilter(
new FilterPredicate("wholesale", FilterOperator.EQUAL, wholesale))
.addSort("name", SortDirection.ASCENDING);
PreparedQuery preparedQuery = this.datastore.prepare(query);
QueryResultIterator<Entity> results = preparedQuery.asQueryResultIterator(fetchOptions);
List<Product> resultBooks = this.entitiesToObjects(results);
Cursor cursor = results.getCursor();
if (cursor != null && resultBooks.size() == 10) {
String cursorString = cursor.toWebSafeString();
return new Result(resultBooks, cursorString);
} else {
return new Result(resultBooks);
}
}
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers(HttpMethod.GET, new String[] { "/products" })
.antMatchers(HttpMethod.GET, new String[] { "/purchases/update" })
.antMatchers(HttpMethod.GET, new String[] { "/purchases/statistics/**" });
}
知道可能是什么问题吗?
解决方案
我认为您可能会根据文档缺少初始化它,它类似于:
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
推荐阅读
- apache-kafka - Kafka集群长时间宕机后消费者是否恢复
- linux - 致命错误:hugetlbfs.h:没有这样的文件或目录
- python - 使用 cxfreeze 将 script.py 转换为可执行文件的问题
- save - CodeIgniter 中的两个提交按钮“保存”和“保存和新建”
- angular - Chart.js - 如何放置标签而不是工具提示?
- vpn - odbc_connect():SQL 错误:[Sybase][ODBC 驱动程序][SQL Anywhere]找不到数据库服务器,SQL 状态 08001
- python - 在python的循环中更改循环变量
- ios - 如何在 PC Windows 上下载和运行 iOS 模拟器
- emacs - 将错误重定向到 org src 中的结果
- pandas - 根据日期和分组过滤熊猫数据框