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

无法读取jar包同级目录下的simbot-bots/master.bot文件 #390

Closed enchantedyou closed 2 years ago

enchantedyou commented 2 years ago

版本号

v3.0.0-beta-RC-SNAPSHOT

附加版本

simbot-component-mirai:3.0.0.0-beta-M1

问题描述

在验证#387 问题时,由于本地验证tx一直报存在风险而且出现无限扫码无法登录的情况,故放到服务器上进行验证,发现启动时报无法找到simbot-bots/.bot文件的错误。(jar包中没有,同级目录下有) image image

复现方式

打包时去除掉jar包中的bot配置文件,放到服务器同级目录下并启动。

相关日志

2022-07-21 13:57:42.874  WARN 1651839 --- [           main] s.a.a.SpringBootApplicationConfiguration : Can not resolve resourc
e path 「simbot-bots/*.bot*」: class path resource [simbot-bots/] cannot be resolved to URL because it does not exist, just us
e empty resources.
2022-07-21 13:57:43.087  INFO 1651839 --- [           main] otEventProviderAutoInstallBuildConfigure : The number of Installab
le Event Provider Factory is 0
2022-07-21 13:57:43.087  INFO 1651839 --- [           main] otEventProviderAutoInstallBuildConfigure : Install Event Providers
 by [installAllEventProviders]
2022-07-21 13:57:43.112  INFO 1651839 --- [           main] s.a.a.SpringBootApplicationConfiguration : The size of providers built is 1
2022-07-21 13:57:43.114  INFO 1651839 --- [           main] s.a.a.SpringBootApplicationConfiguration : Bots all registered. The size of bots: 0
2022-07-21 13:57:43.118  INFO 1651839 --- [           main] s.a.a.SpringBootApplicationConfiguration : Simbot Spring Boot Application built in 577.237207ms
2022-07-21 13:57:43.219  WARN 1651839 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-07-21 13:57:43.878  INFO 1651839 --- [           main] o.s.b.w.e.t.TomcatWebServer              : Tomcat started on port(s): 9030 (http) with context path '/jx3botPlus'
2022-07-21 13:57:43.893  INFO 1651839 --- [           main] c.s.j.p.Jx3PlusApplication               : Started Jx3PlusApplication in 8.295 seconds (JVM running for 8.936)
2022-07-21 13:57:43.896  INFO 1651839 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-07-21 13:57:43.911 ERROR 1651839 --- [           main] o.s.b.SpringApplication                  : Application run failed

java.lang.IllegalStateException: Failed to execute ApplicationRunner
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:771) [spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:758) [spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) [spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) [spring-boot-2.6.4.jar:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) [spring-boot-2.6.4.jar:2.6.4]
        at cn.ssy.jx3.plus.Jx3PlusApplication.main(Jx3PlusApplication.java:24) [jx3-qq-robot-plus-2.0.0-BETA.jar:2.0.0-BETA]
Caused by: love.forte.simbot.SimbotRuntimeException: can't find a valid bot
        at cn.ssy.jx3.plus.util.SimbotUtil.lambda$getBot$0(SimbotUtil.java:101) ~[jx3-qq-robot-plus-2.0.0-BETA.jar:2.0.0-BETA]
        at java.util.Optional.orElseThrow(Optional.java:290) ~[?:1.8.0_301]
        at cn.ssy.jx3.plus.util.SimbotUtil.getBot(SimbotUtil.java:101) ~[jx3-qq-robot-plus-2.0.0-BETA.jar:2.0.0-BETA]
        at cn.ssy.jx3.plus.hook.OnStarted.run(OnStarted.java:34) ~[jx3-qq-robot-plus-2.0.0-BETA.jar:2.0.0-BETA]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768) ~[spring-boot-2.6.4.jar:2.6.4]
        ... 5 more

2022-07-21 13:57:43.940  INFO 1651839 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-07-21 13:57:43.942  INFO 1651839 --- [           main] c.a.d.p.DruidDataSource                  : {dataSource-1} closing ...
2022-07-21 13:57:43.948  INFO 1651839 --- [           main] c.a.d.p.DruidDataSource                  : {dataSource-1} closed

其他补充

No response

ForteScarlet commented 2 years ago

加载资源是通过spring的ResourceLoader进行的。如果希望加载本地文件,请尝试配置自定义扫描路径, 加上 file: 前缀 :

simbot:
   bot-configuration-resources: 
      - file:simbot-bots/**.bot
enchantedyou commented 2 years ago

加上配置后能够正常扫描到了 simbot.bot-configuration-resources=file:simbot-bots/**.bot