2017-02-07 15 views
0

스프링 배치 작업의 단계를 계획하려고합니다. 나는 사용을 시도했다. 하지만 내가 SpringXd에서 그 작업을 실패하려고 할 때. 아래는 내가스프링 스텝 스케줄링

<batch:job id="addB" restartable="false"> 
<batch:step id="AddB" > 
     <tasklet ref="addBTasklet" /> 
</batch:step> 
</batch:job> 

<task:scheduler id="taskScheduler" pool-size="1"/> 
     <task:scheduled-tasks scheduler="taskScheduler">   
     <task:scheduled ref="AddB" method="execute" cron="*/5 * * * * ?"/> 
</task:scheduled-tasks> 

에 직면하고있어 내 코드와 오류는이 오류가 점점 오전 :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'org.springframework.scheduling.support.ScheduledMethodRunnable#0': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.scheduling.support.ScheduledMethodRunnable]:` Constructor threw exception; nested exception is java.lang.NoSuchMethodException: 
org.springframework.batch.core.step.tasklet.TaskletStep.execute() 

답변

0

당신은 할 다음 작업을 시작하는 데 필요한 논리를 구현하는 클래스를 추가 할 필요를 스케줄러는 해당 클래스의 메소드를 호출합니다. 이 새로운 클래스의 내용 :

package mypackage; 

import org.springframework.batch.core.Job; 
import org.springframework.batch.core.JobExecution; 
import org.springframework.batch.core.JobParameters; 
import org.springframework.batch.core.JobParametersBuilder; 
import org.springframework.batch.core.launch.JobLauncher; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.beans.factory.annotation.Qualifier; 
import org.springframework.stereotype.Service; 

import java.util.UUID; 

@Service 
public class TriggerScheduledJob { 

    @Autowired 
    private JobLauncher jobLauncher; 

    @Autowired 
    @Qualifier("addB") 
    private Job addBJob; 

    @Autowired 
    @Qualifier("addC") 
    private Job addCJob; 

    public void triggerAddB() { 
     JobParameters param = new JobParametersBuilder().addString("id", UUID.randomUUID().toString()).toJobParameters(); 
     try { 
      JobExecution execution = jobLauncher.run(addBJob, param); 
      System.out.println("Job executed with exit status = " + execution.getStatus()); 
     } catch (Exception e) { 
      System.out.println("Failed to execute job. " + e.getMessage()); 
     } 
    } 

    public void triggerAddC() { 
     JobParameters param = new JobParametersBuilder().addString("id", UUID.randomUUID().toString()).toJobParameters(); 
     try { 
      JobExecution execution = jobLauncher.run(addCJob, param); 
      System.out.println("Job addC executed with exit status = " + execution.getStatus()); 
     } catch (Exception e) { 
      System.out.println("Failed to execute job. " + e.getMessage()); 
     } 
    } 
} 

는 그 다음이 새로운 빈을 생성 있도록 Spring 애플리케이션 컨텍스트를 조정하고, 그 빈의 관련 메소드를 호출하는 스케줄러를 수정하면 시작할 실제 작업을 트리거 할 :

<batch:job id="addB" restartable="false"> 
    <batch:step id="AddB" > 
     <tasklet ref="addBTasklet" /> 
    </batch:step> 
</batch:job> 

<batch:job id="addC" restartable="false"> 
    <batch:step id="AddC" > 
     <tasklet ref="addCTasklet" /> 
    </batch:step> 
</batch:job> 

<bean id="triggerScheduledJob" class="mypackage.TriggerScheduledJob" /> 

<task:scheduler id="taskScheduler" pool-size="1"/> 
<task:scheduled-tasks scheduler="taskScheduler">   
    <task:scheduled ref="triggerScheduledJob" method="triggerAddB" cron="*/5 * * * * ?"/> 
</task:scheduled-tasks> 
<task:scheduled-tasks scheduler="taskScheduler">   
    <task:scheduled ref="triggerScheduledJob" method="triggerAddC" cron="*/5 * * * * ?"/> 
</task:scheduled-tasks> 

희망을 가져다줍니다.

+0

"addB"및 "addC"의 두 단계가 있고 둘 다 다른 cron 표현식으로 실행되도록 예약해야하는 경우 어떻게됩니까? – srikar

+0

또는 BeanA, BeanB, BeanC, BeanD를 갖고 있으며 각각 특정 시간에 일정을 잡아야합니다. – srikar

+0

안녕하세요. 나는 두 가지 다른 cron 표현을 사용하여 두 가지 다른 작업을 트리거하는 상황을 포함하도록 대답을 확장했습니다. 희망이 도움이됩니다. – aksamit