【发布时间】:2020-11-03 08:07:11
【问题描述】:
鉴于我需要使用多个数据源,我从 Spring Cloud Task Samples 在 IntelliJ Idea 2020.1.3 中编译了以下示例: https://github.com/mminella/spring-cloud-task/tree/master/spring-cloud-task-samples/multiple-datasources
然后我使用 mvn package 将其打包到 JAR 中,将其复制到我启动 docker-compose 的位置(根据官方 SCDF(Spring Cloud Data Flow)本地部署说明)并将其添加到运行以下内容的 SCDF SCDF shell 中的命令:app register --type task --name multiple-datasources --uri file://root/scdf/multiple-datasources-2.3.0-SNAPSHOT.jar.
如图所示,我使用 SCDF 添加了任务:
当我尝试从仪表板运行任务时,执行实例没有提及任何开始时间或结束时间。它也不会在仪表板中显示任何内容。
使用task execution log <instance> 从 SCDF shell 查询日志,显示许多错误。这似乎是最相关的部分:
2020-07-14 02:38:14.403 INFO 63 --- [ main] i.spring.MultipleDataSourcesApplication : Starting MultipleDataSourcesApplication v2.3.0-SNAPSHOT on 5856acfa7c62 with PID 63 (/root/scdf/multiple-datasources-2.3.0-SNAPSHOT.jar started by root in /tmp/289541567048/multiple-datasources-9c75a131-4ea9-40ff-ac42-44729162e6f5)
2020-07-14 02:38:14.407 INFO 63 --- [ main] i.spring.MultipleDataSourcesApplication : No active profile set, falling back to default profiles: default
2020-07-14 02:38:17.242 INFO 63 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
2020-07-14 02:38:18.145 INFO 63 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:hsqldb:mem:testdb', username='sa'
2020-07-14 02:38:18.810 DEBUG 63 --- [ main] o.s.c.t.c.SimpleTaskAutoConfiguration : Using io.spring.configuration.CustomTaskConfigurer TaskConfigurer
2020-07-14 02:38:18.823 DEBUG 63 --- [ main] o.s.c.t.c.DefaultTaskConfigurer : No EntityManager was found, using DataSourceTransactionManager
2020-07-14 02:38:18.928 DEBUG 63 --- [ main] o.s.c.t.r.s.TaskRepositoryInitializer : Initializing task schema for h2 database
2020-07-14 02:38:19.036 ERROR 63 --- [ main] o.s.c.t.listener.TaskLifecycleListener : An event to end a task has been received for a task that has not yet started.
2020-07-14 02:38:19.036 WARN 63 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 31 not found
2020-07-14 02:38:19.036 INFO 63 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Shutting down embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false'
2020-07-14 02:38:19.245 INFO 63 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Shutting down embedded database: url='jdbc:hsqldb:mem:testdb'
2020-07-14 02:38:19.258 ERROR 63 --- [ main] o.s.c.t.listener.TaskLifecycleListener : An event to end a task has been received for a task that has not yet started.
2020-07-14 02:38:19.264 INFO 63 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-14 02:38:19.273 ERROR 63 --- [ main] o.s.boot.SpringApplication : Application run failed
以下错误对我来说尤其突出:
2020-07-14 02:38:19.036 WARN 63 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 31 not found
2020-07-14 02:38:19.258 ERROR 63 --- [ main] o.s.c.t.listener.TaskLifecycleListener : An event to end a task has been received for a task that has not yet started.
2020-07-14 02:38:19.264 INFO 63 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
该示例在application.properties 中有以下几行:
spring.application.name=Demo Multiple DataSources Task
logging.level.org.springframework.cloud.task=DEBUG`
所以如果我没记错的话,调试应该已经启用了。
具体来说我的问题是:
1) 鉴于这是一个示例,即使不进行修改也无法运行,我可能会忽略或做错什么?
2) 如何正确启用 DEBUG?
谢谢
PS:repo 中的示例已经具有 H2 数据库依赖项,在其 pom.xml 中显示为 Registering Custom Spring Cloud Task with Spring Cloud Data Flow 中的答案。
我没有尝试使用当前的引导初始化程序重新创建示例,但是我已经尝试使用最新的初始化程序创建一个简单的 hello-world,但我得到了完全相同的错误。我不认为错误是initializr。
我还没有尝试最后一个建议,覆盖。但是鉴于这是官方示例,我真的需要覆盖默认配置吗?
PPS:我知道我的 SCDF 安装工作正常,因为我能够运行示例中的预打包时间戳程序:https://cloud.spring.io/spring-cloud-task-app-starters/
【问题讨论】:
标签: java spring-boot task spring-cloud-dataflow