simple-robot / simpler-robot

Simple Robot,一个bot风格的Kotlin多平台事件调度框架,异步高效、Java友好!/ A Bot-style Kotlin Multiplatform event scheduling framework, asynchronous and high-performance, java-friendly! 🐱😼😻😸
https://simbot.forte.love
GNU Lesser General Public License v3.0
520 stars 43 forks source link

Simbot的Springboot启动下的JSON的反序列化似乎有问题 #883

Closed Flock-YT closed 3 months ago

Flock-YT commented 3 months ago

是否会提供贡献?

版本号

Simbot Core版本: simbot-core-spring-boot-starter-4.3.0

附加版本

TG组件版本: simbot-component-telegram-core-jvm-0.0.6

涉及的编程语言

Java

项目构建工具

Maven

涉及的组件库

Telegram

问题描述

Springboot模式下启动就报错,搭配的组件为TG组件,未测试其他组件是否有报错.

复现方式

启动即可复现

相关日志

`2024-07-18T16:06:21.145+08:00 ERROR 16380 --- [Eric_TG_Bot] [           main] o.s.boot.SpringApplication               : Application run failed

love.forte.simbot.spring.common.BotConfigResourceLoadOnFailureException: JSON resource [file [C:\Users\mc328\IdeaProjects\Eric_TG_Bot\target\classes\simbot-bots\TG.bot.json]] fails to deserialize, and this may be because a component does not support polymorphic configurations, e.g. the configuration class does not implement class love.forte.simbot.bot.SerializableBotConfiguration, the component does not provide polymorphic serialisation information, etc. The information: Class discriminator was missing and no default serializers were registered in the polymorphic scope of 'SerializableBotConfiguration'.
JSON input: {"componet":"simbot.telegram","ticket":{"token":"XXXXXXX"},"config":{"server":null,"proxy":null,"longPolling":null}}
    at love.forte.simbot.spring.configuration.application.BotAutoLoader.processDecodeFailure(DefaultSimbotApplicationProcessor.kt:317) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    at love.forte.simbot.spring.configuration.application.BotAutoLoader.load$lambda$2(DefaultSimbotApplicationProcessor.kt:212) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822]
    at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:170) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822]
    at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822]
    at kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:214) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822]
    at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:809) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822]
    at love.forte.simbot.spring.configuration.application.BotAutoLoader.load(DefaultSimbotApplicationProcessor.kt:248) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    at love.forte.simbot.spring.configuration.application.DefaultSimbotApplicationProcessor.loadBots(DefaultSimbotApplicationProcessor.kt:126) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    at love.forte.simbot.spring.configuration.application.DefaultSimbotApplicationProcessor.process0(DefaultSimbotApplicationProcessor.kt:122) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    at love.forte.simbot.spring.configuration.application.DefaultSimbotApplicationProcessor.process(DefaultSimbotApplicationProcessor.kt:111) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    at love.forte.simbot.spring.configuration.application.SimbotApplicationRunner.run(SimbotApplicationRunner.kt:56) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    at org.springframework.boot.SpringApplication.lambda$callRunner$4(SpringApplication.java:786) ~[spring-boot-3.3.1.jar:3.3.1]
    at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83) ~[spring-core-6.1.10.jar:6.1.10]
    at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-6.1.10.jar:6.1.10]
    at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:88) ~[spring-core-6.1.10.jar:6.1.10]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) ~[spring-boot-3.3.1.jar:3.3.1]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:786) ~[spring-boot-3.3.1.jar:3.3.1]
    at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:774) ~[spring-boot-3.3.1.jar:3.3.1]
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:na]
    at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na]
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:na]
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[na:na]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) ~[spring-boot-3.3.1.jar:3.3.1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:342) ~[spring-boot-3.3.1.jar:3.3.1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.1.jar:3.3.1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.1.jar:3.3.1]
    at me.lele.eric_tg_bot.EricTgBotApplication.main(EricTgBotApplication.java:13) ~[classes/:na]
Caused by: kotlinx.serialization.json.internal.JsonDecodingException: Class discriminator was missing and no default serializers were registered in the polymorphic scope of 'SerializableBotConfiguration'.
JSON input: {"componet":"simbot.telegram","ticket":{"token":"7290377515:AAH6YdnpEOFq9t2IpuvKS9OoXJGIoWLuTF0"},"config":{"server":null,"proxy":null,"longPolling":null}}
    at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:88) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:75) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at love.forte.simbot.spring.configuration.application.BotAutoLoader.load$lambda$2(DefaultSimbotApplicationProcessor.kt:210) ~[simbot-core-spring-boot-starter-4.3.0.jar:na]
    ... 30 common frames omitted

进程已结束,退出代码为 1`

其他补充

No response

ForteScarlet commented 3 months ago

你的 component 拼错了

ForteScarlet commented 3 months ago

如果修正单词后启动仍有问题的话可随时重启当前issue

Flock-YT commented 3 months ago

修改后依旧有相同报错 此外我的bot.json是从组件代码库里抄的,所以那边可能也得改一下. https://github.com/simple-robot/simbot-component-telegram/tree/dev/main/simbot-component-telegram-core image

ForteScarlet commented 3 months ago

提供下修改后的错误日志、依赖配置等内容

Flock-YT commented 3 months ago

刚刚看错了修改了component单词后的报错并不是原报错而是BotRegisterFailureException

2024-07-18T16:23:53.627+08:00 ERROR 11704 --- [Eric_TG_Bot] [ main] o.s.boot.SpringApplication : Application run failed

love.forte.simbot.bot.BotRegisterFailureException: Failed to register bot from resource [file [C:\Users\mc328\IdeaProjects\Eric_TG_Bot\target\classes\simbot-bots\TG.bot.json]] to manager [love.forte.simbot.component.telegram.core.bot.internal.TelegramBotManagerImpl@35d26ad2] via configuration [SerializableTelegramBotConfiguration(ticket=Ticket(token=XXXXXXXXXX), config=love.forte.simbot.component.telegram.core.bot.SerializableTelegramBotConfiguration$Config@bb25753)]. The information: null at love.forte.simbot.spring.configuration.application.BotAutoLoader.processRegisterBotFailed(DefaultSimbotApplicationProcessor.kt:344) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] at love.forte.simbot.spring.configuration.application.BotAutoLoader.load$lambda$2(DefaultSimbotApplicationProcessor.kt:224) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822] at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:170) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822] at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822] at kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:214) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822] at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:809) ~[kotlin-stdlib-1.9.24.jar:1.9.24-release-822] at love.forte.simbot.spring.configuration.application.BotAutoLoader.load(DefaultSimbotApplicationProcessor.kt:248) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] at love.forte.simbot.spring.configuration.application.DefaultSimbotApplicationProcessor.loadBots(DefaultSimbotApplicationProcessor.kt:126) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] at love.forte.simbot.spring.configuration.application.DefaultSimbotApplicationProcessor.process0(DefaultSimbotApplicationProcessor.kt:122) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] at love.forte.simbot.spring.configuration.application.DefaultSimbotApplicationProcessor.process(DefaultSimbotApplicationProcessor.kt:111) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] at love.forte.simbot.spring.configuration.application.SimbotApplicationRunner.run(SimbotApplicationRunner.kt:56) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] at org.springframework.boot.SpringApplication.lambda$callRunner$4(SpringApplication.java:786) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83) ~[spring-core-6.1.10.jar:6.1.10] at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-6.1.10.jar:6.1.10] at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:88) ~[spring-core-6.1.10.jar:6.1.10] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:786) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:774) ~[spring-boot-3.3.1.jar:3.3.1] at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:na] at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510) ~[na:na] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na] at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:na] at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:na] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na] at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[na:na] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:342) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.1.jar:3.3.1] at me.lele.eric_tg_bot.EricTgBotApplication.main(EricTgBotApplication.java:13) ~[classes/:na] Caused by: java.lang.ExceptionInInitializerError: null at love.forte.simbot.telegram.stdlib.bot.internal.BotImpl.(BotImpl.kt:371) ~[simbot-component-telegram-stdlib-jvm-0.0.6.jar:na] at love.forte.simbot.telegram.stdlib.bot.BotFactory.create(BotFactory.kt:36) ~[simbot-component-telegram-stdlib-jvm-0.0.6.jar:na] at love.forte.simbot.component.telegram.core.bot.internal.TelegramBotManagerImpl.register$createBot(TelegramBotManagerImpl.kt:69) ~[simbot-component-telegram-core-jvm-0.0.6.jar:na] at love.forte.simbot.component.telegram.core.bot.internal.TelegramBotManagerImpl.access$register$createBot(TelegramBotManagerImpl.kt:45) ~[simbot-component-telegram-core-jvm-0.0.6.jar:na] at love.forte.simbot.component.telegram.core.bot.internal.TelegramBotManagerImpl$register$$inlined$computeValue$1.invoke(maps.jvm.kt:61) ~[simbot-component-telegram-core-jvm-0.0.6.jar:na] at love.forte.simbot.component.telegram.core.bot.internal.TelegramBotManagerImpl$inlined$sam$i$java_util_function_BiFunction$0.apply(maps.jvm.kt) ~[simbot-component-telegram-core-jvm-0.0.6.jar:na] at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1916) ~[na:na] at love.forte.simbot.component.telegram.core.bot.internal.TelegramBotManagerImpl.register(TelegramBotManagerImpl.kt:109) ~[simbot-component-telegram-core-jvm-0.0.6.jar:na] at love.forte.simbot.component.telegram.core.bot.TelegramBotManager.register(TelegramBotManager.kt:71) ~[simbot-component-telegram-core-jvm-0.0.6.jar:na] at love.forte.simbot.component.telegram.core.bot.TelegramBotManager.register(TelegramBotManager.kt:44) ~[simbot-component-telegram-core-jvm-0.0.6.jar:na] at love.forte.simbot.spring.configuration.application.BotAutoLoader.load$lambda$2(DefaultSimbotApplicationProcessor.kt:221) ~[simbot-core-spring-boot-starter-4.3.0.jar:na] ... 30 common frames omitted Caused by: java.lang.IllegalStateException: Failed to find HTTP client engine implementation in the classpath: consider adding client engine dependency. See https://ktor.io/docs/http-client-engines.html at io.ktor.client.HttpClientJvmKt.(HttpClientJvm.kt:43) ~[ktor-client-core-jvm-2.3.11.jar:2.3.11] ... 41 common frames omitted

进程已结束,退出代码为 1

依赖相关: image

bot.json配置相关: image image

ForteScarlet commented 3 months ago

你需要添加一个 Ktor 的 HTTP Client 依赖,可以参考 QQ组件 中有关 Ktor 的说明,都是类似的,只不过TG组件不要求WebSocket的支持

Flock-YT commented 3 months ago

emmmm添加依赖后虽然开启来不报错了但是他并没有驻留而是直接进程结束了,不确定是不是我哪里配置错了.

2024-07-18T16:39:26.627+08:00 INFO 30808 --- [Eric_TG_Bot] [ main] m.lele.eric_tg_bot.EricTgBotApplication : Starting EricTgBotApplication using Java 21.0.3 with PID 30808 (C:\Users\mc328\IdeaProjects\Eric_TG_Bot\target\classes started by mc328 in C:\Users\mc328\IdeaProjects\Eric_TG_Bot) 2024-07-18T16:39:26.629+08:00 INFO 30808 --- [Eric_TG_Bot] [ main] m.lele.eric_tg_bot.EricTgBotApplication : No active profile set, falling back to 1 default profile: "default" 2024-07-18T16:39:27.471+08:00 INFO 30808 --- [Eric_TG_Bot] [ main] love.forte.simbot.utils.BlockingRunner : Blocking runner wait timeout is enabled with wait timeout 1m. You can enable debug logging for 'love.forte.simbot.utils.BlockingRunner' for more stack information or disable it with the JVM parameter '-Dsimbot.blockingRunner.disableWaitTimeout=true'. 2024-07-18T16:39:27.609+08:00 INFO 30808 --- [Eric_TG_Bot] [ main] m.lele.eric_tg_bot.EricTgBotApplication : Started EricTgBotApplication in 1.258 seconds (process running for 1.837) 2024-07-18T16:39:27.696+08:00 INFO 30808 --- [Eric_TG_Bot] [ main] l.f.s.s.c.application.BotAutoLoader : The number of registered bots is 1 2024-07-18T16:39:27.699+08:00 INFO 30808 --- [Eric_TG_Bot] [ main] l.f.s.s.c.a.SimbotApplicationRunner : Launch application SpringApplication(isActive=true, isCompleted=false, eventDispatcher=SimpleEventDispatcher, components=Components(values=[TelegramComponent(id=simbot.telegram)]), plugins=Plugins(values=[love.forte.simbot.component.telegram.core.bot.internal.TelegramBotManagerImpl@5927f904])) with mode: NONE

进程已结束,退出代码为 0

Flock-YT commented 3 months ago

补充一下我的配置

Main image bot.json image Springboot配置 image 目录结构 image 依赖 image

ForteScarlet commented 3 months ago

这是正常现象,参考集成Spring的可配置项 simbot.application.application-launch-mode

以及,顺带一提,如果你希望通过组件主动抓取事件来达成“事件订阅”的效果,你的配置文件需要配置 longPolling,比如:

{
  // 其他省略
  "config": {
    "longPolling": {
      "limit": 100, // 每次最大抓取事件量
      "timeout": 3600, // 每次抓取等待超时时间,不配置默认10分钟,单位秒
      "allowedUpdates": null, // 允许抓取的事件的列表,List<String> 格式,默认为 `null` 即全部抓取
    }
  }
}
Flock-YT commented 3 months ago

oo抱歉,因为早期用simbot的时候不需要特别配置THREAD模式,所以没回去仔细看文档,目前看来问题应该是解决了,感谢.

(希望可以在tg core的仓库中标注一下要添加Ktor 的 HTTP Client 依赖以防再有我这样的小白出现:)

ForteScarlet commented 3 months ago

TG组件毕竟还在早期,我甚至都没想到会有人这么快就用(