GAE-此线程未注册API环境 [英] GAE - No API environment is registered for this thread

查看:180
本文介绍了GAE-此线程未注册API环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Google App Engine部署到Google Cloud的spring-boot应用程序.有一个具有多个实体的数据存储. 当我尝试通过我的应用程序检索数据(应用程序上传到AppEngine而不是本地)时,总是会引发错误-

I have an spring-boot application deployed to google cloud using google app engine. There is a datastore with multiple entities. When I try to retrieve data through my app (app is uploaded to appengine, not locally) it always throws an error -

发生意外错误(类型=内部服务器错误,状态= 500). 没有为该线程注册任何API环境.

There was an unexpected error (type=Internal Server Error, status=500). No API environment is registered for this thread.

我正在尝试以这种方式工作:

I am trying to make it work this way:

@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/**" });
}

任何想法可能是什么问题?

Any idea what could be the problem?

推荐答案

我认为根据

I think you might be missing inizialiting it according to the documentation, it would be something like:

Datastore datastore = DatastoreOptions.getDefaultInstance().getService();

这篇关于GAE-此线程未注册API环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆