本文整理匯總了Java中org.springframework.batch.core.launch.JobLauncher類的典型用法代碼示例。如果您正苦於以下問題:Java JobLauncher類的具體用法?Java JobLauncher怎麽用?Java JobLauncher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JobLauncher類屬於org.springframework.batch.core.launch包,在下文中一共展示了JobLauncher類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("chunkJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例2: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("taskletJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例3: runner
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
CommandLineRunner runner(JobLauncher launcher,
Job job,
@Value("${file}") File in,
JdbcTemplate jdbcTemplate) {
return args -> {
JobExecution execution = launcher.run(job,
new JobParametersBuilder()
.addString("file", in.getAbsolutePath())
.toJobParameters());
System.out.println("execution status: " + execution.getExitStatus().toString());
List<Person> personList = jdbcTemplate.query("select * from PEOPLE", (resultSet, i) -> new Person(resultSet.getString("first"),
resultSet.getString("last"),
resultSet.getString("email")));
personList.forEach(System.out::println);
};
}
示例4: run
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
private static void run(final String[] args, final String payloadFilePath) throws Exception {
try(final ConfigurableApplicationContext context = SpringApplication.run(PayloadJobMain.class, args)) {
final List<JobLaunchingData> jobLaunchingDataList = parseJobParameters(payloadFilePath);
final JobLauncher jobLauncher = context.getBean(JobLauncher.class);
for(final JobLaunchingData jobLaunchingData : jobLaunchingDataList) {
final String jobName = jobLaunchingData.getJobName();
final JobParameters jobParameters = jobLaunchingData.getJobParameters();
final Job job = context.getBean(jobName, Job.class);
final JobExecution jobExecution = jobLauncher.run(job, jobParameters);
awaitTermination(jobExecution, Duration.ofMinutes(30));
if (!jobExecution.getExitStatus().equals(ExitStatus.COMPLETED)) {
throw new JobExecutionUnsuccessfullException(String.format("Job %s was unsuccessful with status %s.", jobName, jobExecution.getExitStatus()));
}
}
}
}
示例5: testRenamePrefix
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
@Test
public void testRenamePrefix() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.name:batchtest",
"spring.batch.schema:classpath:batch/custom-schema-hsql.sql",
"spring.batch.tablePrefix:PREFIX_");
this.context.register(TestConfiguration.class,
EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(JobLauncher.class)).isNotNull();
assertThat(new JdbcTemplate(this.context.getBean(DataSource.class))
.queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
JobExplorer jobExplorer = this.context.getBean(JobExplorer.class);
assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty();
JobRepository jobRepository = this.context.getBean(JobRepository.class);
assertThat(jobRepository.getLastJobExecution("test", new JobParameters()))
.isNull();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:22,代碼來源:BatchAutoConfigurationTests.java
示例6: init
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
@Before
public void init() throws Exception {
this.context.register(BatchConfiguration.class);
this.context.refresh();
JobRepository jobRepository = this.context.getBean(JobRepository.class);
this.jobLauncher = this.context.getBean(JobLauncher.class);
this.jobs = new JobBuilderFactory(jobRepository);
PlatformTransactionManager transactionManager = this.context
.getBean(PlatformTransactionManager.class);
this.steps = new StepBuilderFactory(jobRepository, transactionManager);
this.step = this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
return null;
}
}).build();
this.job = this.jobs.get("job").start(this.step).build();
this.jobExplorer = this.context.getBean(JobExplorer.class);
this.runner = new JobLauncherCommandLineRunner(this.jobLauncher,
this.jobExplorer);
this.context.getBean(BatchConfiguration.class).clear();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:24,代碼來源:JobLauncherCommandLineRunnerTests.java
示例7: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("multiResourceItemReaderJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例8: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("customReaderWriterProcesorJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例9: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("customListeners");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例10: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("flatFileItemWriterJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例11: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("parallelStepsJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例12: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("secuentialControlFlow");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例13: main
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
public static void main(String[] args) {
String[] springConfig = { "spring/batch/jobs/job-config.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("xmlReadersWritersJob");
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("Exit Status : " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
示例14: resolveJobLauncher
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
private JobLauncher resolveJobLauncher() {
if (jobLauncherRef != null) {
JobLauncher jobLauncher = getCamelContext().getRegistry().lookupByNameAndType(jobLauncherRef, JobLauncher.class);
if (jobLauncher == null) {
throw new IllegalStateException(String.format("No JobLauncher named %s found in the registry.", jobLauncherRef));
}
return jobLauncher;
}
if (defaultResolvedJobLauncher != null) {
return defaultResolvedJobLauncher;
}
if (allResolvedJobLaunchers.size() == 1) {
return allResolvedJobLaunchers.values().iterator().next();
} else if (allResolvedJobLaunchers.size() > 1) {
throw new IllegalStateException("Expected single jobLauncher instance. Found: " + allResolvedJobLaunchers.size());
}
throw new IllegalStateException("Cannot find Spring Batch JobLauncher.");
}
示例15: shouldInjectJobLauncherByReferenceName
import org.springframework.batch.core.launch.JobLauncher; //導入依賴的package包/類
@Test
public void shouldInjectJobLauncherByReferenceName() throws Exception {
// Given
context().addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:launcherRefTest").to("spring-batch:mockJob?jobLauncher=#alternativeJobLauncher");
}
});
// When
template.sendBody("direct:launcherRefTest", "Start the job, please.");
// Then
SpringBatchEndpoint batchEndpoint = context().getEndpoint("spring-batch:mockJob?jobLauncher=#alternativeJobLauncher", SpringBatchEndpoint.class);
JobLauncher batchEndpointJobLauncher = (JobLauncher) FieldUtils.readField(batchEndpoint, "jobLauncher", true);
assertSame(alternativeJobLauncher, batchEndpointJobLauncher);
}