问题
I'm having Spring Batch job
that is also dataflow task
. When I run this job everything seems OK, In Tasks
> Executions
I can see that tasks finished successfully. On the other hand when I go to Jobs
tabs I'm getting this error (in command line):
java.lang.NullPointerException: null
at org.springframework.cloud.dataflow.server.service.impl.DefaultTaskJobService.getTaskJobExecution(DefaultTaskJobService.java:240) ~[spring-cloud-dataflow-server-core-1.2.2.RELEASE.jar!/:1.2.2.RELEASE]
at org.springframework.cloud.dataflow.server.service.impl.DefaultTaskJobService.getTaskJobExecutionsForList(DefaultTaskJobService.java:233) ~[spring-cloud-dataflow-server-core-1.2.2.RELEASE.jar!/:1.2.2.RELEASE]
at org.springframework.cloud.dataflow.server.service.impl.DefaultTaskJobService.listJobExecutions(DefaultTaskJobService.java:103) ~[spring-cloud-dataflow-server-core-1.2.2.RELEASE.jar!/:1.2.2.RELEASE]
at org.springframework.cloud.dataflow.server.controller.JobExecutionController.list(JobExecutionController.java:91) ~[spring-cloud-dataflow-server-core-1.2.2.RELEASE.jar!/:1.2.2.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]
Spring Dataflow version = 1.2.2
回答1:
I just ran into this issue a couple of days ago. The reason you get a null pointer exception is because when you ran your task, it's execution got inserted into the batch and task tables, except for the TASK_TASK_BATCH table. When you try to access the Jobs tab in DataFlow it reads from this table and cannot find the record so it throws the null pointer.
For me the root cause was because I removed the spring-boot-starter-parent from my spring boot application (since I needed to provide my own). In the process of doing so, I removed the spring-cloud-starter-task dependency, in exchange for the spring-cloud-task-core, thinking this was all I needed seeing as it compiled and the task ran just fine. What I eventually found out was that the spring-cloud-starter-task not only contains the spring-cloud-task-core, but also the spring-cloud-task-batch and the spring-cloud-task-stream. In my case, I was missing spring-cloud-task-batch which is what inserts the records into the TASK_TASK_BATCH table. So I simply removed the spring-cloud-task-core, and re-added spring-cloud-starter-task which solved the issue.
It's worth mentioning that one will also have to go and fix the data, by either manually adding those missing records to the TASK_TASK_BATCH table, or resetting your batch/task tables/sequences. Hope this helps!
来源:https://stackoverflow.com/questions/47570735/dataflow-tasks-are-not-working-with-spring-batch