Spring Boot Firebase JsonWriter

时间:2017-11-17 14:33:17

标签: firebase spring-boot firebase-realtime-database

我有一个非常简单的Spring启动应用程序,具有以下依赖项。

compile(
    "org.springframework.boot:spring-boot-starter-actuator",
    "org.springframework.boot:spring-boot-starter-data-rest",
    "org.springframework.boot:spring-boot-configuration-processor",
    "org.jetbrains.kotlin:kotlin-stdlib-jre8:2.1.3",
    "org.jetbrains.kotlin:kotlin-reflect:2.1.3",
    "io.reactivex.rxjava2:rxjava:2.1.3",
    "com.google.firebase:firebase-admin:5.5.0"
)

我只是想把POJO放到我的实时firebase数据库上。

val db = FirebaseDatabase.getInstance()
db.reference.setValue(
    SomePojo().apply {
        name = ""
        someOtherProp = "Some other value"
    },
    { err, _ ->
        println("error=$err")
    })

然而,在日志中,我可以看到lib内部出现了问题。

2017-11-17 15:18:08.376  INFO 1377 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-11-17 15:18:08.385  INFO 1377 --- [           main] be.topradio.metadata.AppKt               : Started AppKt in 19.051 seconds (JVM running for 19.615)
2017-11-17 15:18:08.908 ERROR 1377 --- [eDatabaseWorker] c.google.firebase.database.core.RunLoop  : Uncaught exception in Firebase Database runloop (5.5.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) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.util.JsonMapper.serializeJsonValue(JsonMapper.java:61) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.util.JsonMapper.serializeJson(JsonMapper.java:41) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.util.GAuthToken.serializeToString(GAuthToken.java:67) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.core.JvmAuthTokenProvider.wrapOAuthToken(JvmAuthTokenProvider.java:86) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.core.JvmAuthTokenProvider.getToken(JvmAuthTokenProvider.java:66) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.core.Context$1.getToken(Context.java:63) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.connection.PersistentConnectionImpl$1.run(PersistentConnectionImpl.java:481) ~[firebase-admin-5.5.0.jar:na]
    at com.google.firebase.database.connection.util.RetryHelper$1.run(RetryHelper.java:93) ~[firebase-admin-5.5.0.jar:na]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_60]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_60]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_60]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.8.0_60]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_60]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

TL;博士

我打算通过排除Spring Boot配置处理器引入的依赖项来摆脱这个错误:

compile('org.springframework.boot:spring-boot-configuration-processor') {
       exclude group: 'com.vaadin.external.google'
}

另外(虽然我没有看到这个错误),我相信它也应该被排除在Spring Boot的初学者测试依赖项之外。

testCompile('org.springframework.boot:spring-boot-starter-test') {
       exclude group: 'com.vaadin.external.google'
}

我是如何找到这个

StackOverflow question you visited开始,我开始在包' org.json'中查找类JSONStringer的潜在问题。所以我在想依赖于' 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依赖关系才使用此软件包。我怀疑这个问题并不是Google dependecies中的版本冲突,所以我查找了Spring可能与org.json pacakage发生的冲突。

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

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