我可以在同一个流

时间:2016-02-04 12:43:07

标签: java spring-batch spring-java-config

我无法想象如何在同一作业中两次使用相同的CustomDecider。如果我创建两个不同的JobExecutionDecider实现,其内部具有相同的逻辑,那么我可以使用。 JobExecutionDecider是否设计为以这种方式工作?如果没有,我必须在下面更改以便... next(customDecider())。on(" go")。to(stepA).next(customDecider())...和避免异常StartLimitExceededException?

2016-02-04 06:04:01.222 ERROR 11476 --- [           main] o.s.batch.core.job.AbstractJob           : Encountered fatal error executing job
org.springframework.batch.core.JobExecutionException: Flow execution ended unexpectedly
       at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:140) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:215) [spring-boot-autoconfigure-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:232) [spring-boot-autoconfigure-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:124) [spring-boot-autoconfigure-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:118) [spring-boot-autoconfigure-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:788) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:775) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:366) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at com.example.DemoApplication.main(DemoApplication.java:10) [classes/:na]

Caused by: org.springframework.batch.core.job.flow.FlowExecutionException: Ended flow=job1 at state=job1.stepA with exception
       at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:178) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       ... 16 common frames omitted

Caused by: org.springframework.batch.core.StartLimitExceededException: Maximum start limit exceeded for step: stepAStartMax: 2
       at org.springframework.batch.core.job.SimpleStepHandler.shouldStart(SimpleStepHandler.java:227) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:126) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
       ... 18 common frames omitted


2016-02-04 06:04:01.237  INFO 11476 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=job1]] completed with the following parameters: [{}] and the following status: [FAILED]

       //I increased startLimit(2) because I read Maximum start limit exceeded for step: stepAStartMax: 1
       @Bean
       public Step stepA(ItemReader<String> readerA, ItemWriter<String> writerA,
                     StepExecutionListener stepListener) {
              return stepBuilderFactory.get("stepA").<String, String> chunk(1)
                           .reader(readerA).writer(writerA).allowStartIfComplete(false)
                           .startLimit(2).listener(stepListener).build();
       }

       @Bean
       public Job job(Step stepMheFiles, Step stepA, Step stepB,
                     JobExecutionListener jobListener, JobExecutionDecider customDecider) throws Exception {
              return jobBuilderFactory
                           .get("job1")
                            //******* The next line is working but with two classes
                            //.start(stepMheFiles).next(customDeciderA()).on("goA").to(stepA).next(customDeciderB()).on("goB").to(stepB).build().build();
                            //****** The next line causes the issue I am talking
                            .start(anyTasklet).next(customDecider()).on("go").to(stepA).next(customDecider()).on("go").to(anyOtherStep).build().build();
       }

       @Bean
       public JobExecutionDecider customDecider() throws Exception {
              return new CustomDecider();
       }

       //******** If I created two classes (CustomDeciderA and CustomDeciderB) then it will work
       @Bean
       public JobExecutionDecider customDeciderA() throws Exception {
              return new CustomDeciderA();
       }

       @Bean
       public JobExecutionDecider customDeciderB() throws Exception {
              return new CustomDeciderB();
       }


       public class CustomDecider implements JobExecutionDecider {
       @Override
       public FlowExecutionStatus decide(JobExecution jobExecution,
                     StepExecution stepExecution) {
              return new FlowExecutionStatus("go");
       }

       //********* note that CustomDeciderA and CustomDeciderB are identical except for the names
       public class CustomDeciderA implements JobExecutionDecider {
       @Override
       public FlowExecutionStatus decide(JobExecution jobExecution,
                     StepExecution stepExecution) {
              return new FlowExecutionStatus("goA");
       }

       public class CustomDeciderB implements JobExecutionDecider {
       @Override
       public FlowExecutionStatus decide(JobExecution jobExecution,
                     StepExecution stepExecution) {
              return new FlowExecutionStatus("goB");
       }

***首次建议后编辑: 我改变了下面的代码,现在我得到&#34;期望单个匹配的bean但是找到2:customDeciderA,customDeciderB&#34;。

.start(stepMheFiles).next(customDeciderA()).on("go").to(stepA).next(customDeciderB()).on("go").to(stepB).build().build();

       @Bean
       public JobExecutionDecider customDeciderA() throws Exception {
              return new CustomDecider();
       }

       @Bean
       public JobExecutionDecider customDeciderB() throws Exception {
              return new CustomDecider();
       }


No qualifying bean of type [org.springframework.batch.core.job.flow.JobExecutionDecider] is defined: expected single matching bean but found 2: customDeciderA,customDeciderB

2016-02-04 10:09:18.637 ERROR 9984 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'job' defined in com.example.BatchConfiguration: Unsatisfied dependency expressed through constructor argument with index 4 of type [org.springframework.batch.core.job.flow.JobExecutionDecider]: : No qualifying bean of type [org.springframework.batch.core.job.flow.JobExecutionDecider] is defined: expected single matching bean but found 2: customDeciderA,customDeciderB; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.job.flow.JobExecutionDecider] is defined: expected single matching bean but found 2: customDeciderA,customDeciderB
       at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
       at com.example.DemoApplication.main(DemoApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.job.flow.JobExecutionDecider] is defined: expected single matching bean but found 2: customDeciderA,customDeciderB
       at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1126) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
       ... 18 common frames omitted

2016-02-04 10:09:18.653  INFO 9984 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath:

0 个答案:

没有答案