Spring启动时的Firebase在初始化期间出错 [英] Firebase in Spring boot gives error during initalization

查看:231
本文介绍了Spring启动时的Firebase在初始化期间出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Spring Boot应用中设置Firebase。我正在按照此处文档中提供的代码段进行操作。这就是我的pom的样子:

I'm trying to set up Firebase in Spring Boot app. I'm following the code snippets given in the documentation here. This is how my pom looks:

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>5.2.0</version>
</dependency>

我用来初始化firebase的代码:

The code that I run to initialise firebase:

@PostConstruct
    public void init() {
        InputStream serviceAccount = FirebaseConfig.class.getClassLoader().getResourceAsStream(configPath);

        FirebaseOptions options = null;
        try {
            options = new FirebaseOptions.Builder()
                    .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
                    .setDatabaseUrl(databaseUrl)
                    .build();
        } catch (IOException e) {
            e.printStackTrace();
        }
        FirebaseApp.initializeApp(options);

    }

启动时 FirebaseApp.initializeApp 抛出以下错误:


[错误] RunLoop:Firebase数据库runloop中未捕获的异常
(5.2 .0)。请向firebase-database-client@google.com报告
java.lang.NoSuchMethodError:
org.json.JSONStringer.object()Lorg / json / JSONWriter;在在
com.google.firebase.database.util.JsonMapper.serializeJsonValue(JsonMapper
com.google.firebase.database.util.JsonMapper.serializeJsonValue(JsonMapper.java:72)
。 java:61)
at
com.google.firebase.database.util.JsonMapper.serializeJson(JsonMapper.java:41)

[ERROR] RunLoop: Uncaught exception in Firebase Database runloop (5.2.0). Please report to firebase-database-client@google.com java.lang.NoSuchMethodError: org.json.JSONStringer.object()Lorg/json/JSONWriter; at com.google.firebase.database.util.JsonMapper.serializeJsonValue(JsonMapper.java:72) at com.google.firebase.database.util.JsonMapper.serializeJsonValue(JsonMapper.java:61) at com.google.firebase.database.util.JsonMapper.serializeJson(JsonMapper.java:41)

我试图包含 org.json 但没有运气。

I have tried to include org.json but with no luck.

推荐答案

不确定你是否找到了答案Raj

Not sure if you found the answer Raj

通过排除Spring Boot配置处理器引入的依赖关系,我即将摆脱这个错误并且(虽然我在排除第一个之后不再看到此错误)也从Spring启动启动测试中排除(如果使用):

I was about to get rid of this error by excluding a dependency pulled in by Spring Boot's configuration processor and (though I did not see this error anymore after excluding just the first) also exclude from Spring boot starter test (if used):

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <version>1.5.8.RELEASE</version>
        <scope>compile</scope>
        <exclusions>
          <exclusion> 
            <groupId>com.vaadin.external.google</groupId>
            <artifactId>android.json</artifactId>
          </exclusion>
        </exclusions> 
      </dependency>
    ...
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <version>1.5.8.RELEASE</version>
        <scope>test</scope>
        <exclusions>
          <exclusion> 
            <groupId>com.vaadin.external.google</groupId>
            <artifactId>android.json</artifactId>
          </exclusion>
        </exclusions> 
      </dependency>
    ...
  </dependencies>
</project>

请注意:我还没有测试过这个精确的pom片段因为我是使用gradle而不是maven,但这应该是正确的。

Please note: I haven not tested this exact pom snippet because I am using gradle instead of maven, but this should be right.

阅读你的问题和其他答案,我开始在包'org.json'中查找类JSONStringer的潜在问题。所以我在想依赖于'org.json'的依赖项的版本冲突

Reading your question and other answers, I began looking into potential issue with class JSONStringer in package 'org.json'. So I was thinking a version conflict of a dependency that depended on 'org.json'

运行 ./ gradlew dependencyInsight --dependency org.json ,我收到:

org.json:json:20160810 -> 20140107
+--- com.google.cloud:google-cloud-core:1.7.0
|    +--- com.google.cloud:google-cloud-storage:1.7.0
|    |    \--- com.google.firebase:firebase-admin:5.5.0
|    |         \--- compile
|    +--- com.google.cloud:google-cloud-firestore:0.25.0-beta
|    |    \--- com.google.firebase:firebase-admin:5.5.0 (*)
|    +--- com.google.cloud:google-cloud-core-http:1.7.0
|    |    +--- com.google.cloud:google-cloud-storage:1.7.0 (*)
|    |    \--- com.google.cloud:google-cloud-firestore:0.25.0-beta (*)
|    \--- com.google.cloud:google-cloud-core-grpc:1.7.0
|         \--- com.google.cloud:google-cloud-firestore:0.25.0-beta (*)
\--- com.google.firebase:firebase-admin:5.5.0 (*)

(*) - dependencies omitted (listed previously)

所以只有谷歌依赖项正在使用此包。我怀疑这个问题不是google dependecies中的版本冲突,所以我查找了Spring可能与org.json pacakage发生的冲突。

so only the google dependencies were using this package. I suspected that the issue wasn't a version conflict in the google dependecies, so I looked for conflicts that Spring may have with the org.json pacakage.

Google搜索'Spring boot org.json'引导我进入 Github问题关于与json库的冲突。该问题提到对于spring-boot-starter-test,因为org.skyscreamer:jsonassert:1.4.0是必需的,不包括com.vaadin.external.google:android-json:0.0.20131108.vaadin1。

Google search for 'Spring boot org.json' led me to a Github issue about conflicts with json library. The issue mentioned that for spring-boot-starter-test since "org.skyscreamer:jsonassert:1.4.0 is required, exclude com.vaadin.external.google:android-json:0.0.20131108.vaadin1."

从那时起,我跑了:`./gradlew dependencyInsight --dependency'com.vaadin.external.google'引用了'spring-boot-configuration-processor'。

From that, I ran: `./gradlew dependencyInsight --dependency 'com.vaadin.external.google' which referenced 'spring-boot-configuration-processor'.

这篇关于Spring启动时的Firebase在初始化期间出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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