【问题标题】:SpringBoot - Firestore : Firebase app not initialize on tomcat serverSpringBoot - Firestore:Firebase 应用程序未在 tomcat 服务器上初始化
【发布时间】:2019-08-15 01:03:18
【问题描述】:

我在我的 Spring Boot 应用程序上使用 Cloud Firestore;当我在本地测试时,它运行正常。我在我的 tomcat 实例 vm 上部署了我的 war 文件,我收到此错误 FirebaseApp with name [DEFAULT] doesn't exist。我关注此链接解决方案https://firebase.google.com/docs/firestore/quickstart,但无法在服务器上运行。 我使用了很多解决方案,但我总是遇到同样的错误。 我需要帮助来解决这个问题。 我使用此代码来初始化 firebase-admin-sdk

【问题讨论】:

标签: java firebase google-cloud-firestore google-compute-engine


【解决方案1】:

这是我的java主类

public static void main(String[] args) {
SpringApplication.run(BemanagementfirestoreApplication.class, args);
    try {
        InputStream serviceAccount = new FileInputStream("/Users/macbookpro/MyjavaProjet/apikey.json");
        GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(credentials)
                .build();
        FirebaseApp.initializeApp(options);
        Firestore db = FirestoreClient.getFirestore();
    } catch (IOException e) {
        e.printStackTrace();
}
}

【讨论】:

  • 主函数在WAR部署中不会被执行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多