【问题标题】:Error when launching tasks with multiple arguments from UI spring cloud dataflow从 UI spring 云数据流启动具有多个参数的任务时出错
【发布时间】:2019-02-25 15:35:23
【问题描述】:

我有一个带有 2 个参数的批处理作业。当我在直接运行 jar 文件时传递这些参数时,它可以工作。此外,当我通过 Spring Cloud 数据流的外壳传递这些参数时,它可以工作:

dataflow:>task launch --name adv-load --arguments "appnexus_seat=SEAT_MIQ_1 last_modified=2018/08/10"
Launched task 'adv-load'

但是当我在从 UI 运行任务时传递类似的参数时,它会失败。例如,在 UI 中,我通过:appnexus_seat 和 last_modified 作为 2 个键,其值与上述相同,但日期不同,因此它认为它不是同一个工作。这失败了。

不过,我确实设法找到了问题所在。当我通过 shell 运行任务时,在日志中我得到这个:

2018-09-21 14:04:50.970  INFO 4035 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: [appnexus_seat=SEAT_MIQ_1, last_modified=2018/08/10, --spring.cloud.task.executionid=5]
2018-09-21 14:04:51.073  INFO 4035 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=advertiserLoadJob]] launched with the following parameters: [{appnexus_seat=SEAT_MIQ_1, -spring.cloud.task.executionid=5, last_modified=2018/08/10}]
2018-09-21 14:04:51.081  INFO 4035 --- [           main] o.s.c.t.b.l.TaskBatchExecutionListener   : The job execution id 5 was run within the task execution 5
2018-09-21 14:04:51.116  INFO 4035 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [advertiserLoadStep1]

而当我通过 Ui 运行它时,我得到了这个:

2018-09-21 14:05:57.417  INFO 4924 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: [appnexus_seat=SEAT_MIQ_1,last_modified=2018/08/10, --spring.cloud.task.executionid=6]
2018-09-21 14:05:57.518  INFO 4924 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=advertiserLoadJob]] launched with the following parameters: [{appnexus_seat=SEAT_MIQ_1,last_modified=2018/08/10, -spring.cloud.task.executionid=6}]
2018-09-21 14:05:57.528  INFO 4924 --- [           main] o.s.c.t.b.l.TaskBatchExecutionListener   : The job execution id 6 was run within the task execution 6
2018-09-21 14:05:57.586  INFO 4924 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [advertiserLoadStep1]
2018-09-21 14:05:57.653 ERROR 4924 --- [           main] o.s.batch.core.step.AbstractStep         : Encountered an error executing step advertiserLoadStep1 in job advertiserLoadJob

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.advertiserLoadTasklet': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mediaiq.appnexus.load.client.AppnexusRestClient com.mediaiq.appnexus.batch.tasklet.AbstractPageLoadTasklet.appnexusClient; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'JOB' defined in class path resource [com/mediaiq/appnexus/load/config/AppnexusRestClientFactory.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.mediaiq.appnexus.value.AppnexusSeat]: : Failed to convert value of type [java.lang.String] to required type [com.mediaiq.appnexus.value.AppnexusSeat]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.mediaiq.appnexus.value.AppnexusSeat]: no matching editors or conversion strategy found; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type [java.lang.String] to required type [com.mediaiq.appnexus.value.AppnexusSeat]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.mediaiq.appnexus.value.AppnexusSeat]: no matching editors or conversion strategy found

如果您查看差异,您会发现当我通过 shell 运行它时,它会在 2 个参数之间提供一个空格,而当我通过 Ui 运行它时它不会。不提供此空间会导致问题,因为第一个参数的值变为“SEAT_MIQ_1,last_modified=2018/08/10”,而不仅仅是“SEAT_MIQ_1”,而 last_modified 是另一个参数。

请告诉我如何解决这个问题。谢谢。 :)

【问题讨论】:

  • 我当时添加了一个答案。既然您在评论中说:“嘿,非常感谢。我也尝试使用 v1.7.0.M1 并且它有效。我想这是当前版本的错误。非常感谢!”。请采纳答案,见stackoverflow.com/help/someone-answers

标签: spring spring-batch spring-cloud spring-cloud-dataflow spring-cloud-task


【解决方案1】:

当您从 UI 运行任务时,您需要在单独的字段中指定每个参数:

这将正确地将参数传递给您的任务。

【讨论】:

  • 嘿,我一直在这样做。尽管如此,它并没有在参数之间添加空格,而只是一个逗号。
  • 我用 1.7.0.M1 版本测试了我的答案,它工作正常。你用的是哪个版本的spring cloud数据流?
  • 数据流服务器:1.6.3
  • 另外,当您使用参数运行作业时,您能否向我显示执行日志,其中显示了命令行参数和所采用的作业参数?谢谢
  • 我的任务实际上是一个 hello world Spring Batch 作业,它接受两个参数 name1name2 并打印:Hello name1 name2。这是日志中的命令:2018-09-21 13:47:41.996 INFO 3982 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job]] launched with the following parameters: [{name2=bar, -spring.cloud.task.executionid=1, name1=foo}]。我刚刚使用 1.6.3.RELEASE 版本进行了测试,它也按预期工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多