83 lines
3.4 KiB
Java
83 lines
3.4 KiB
Java
package com.wb.domainserver;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.batch.core.*;
|
|
import org.springframework.batch.core.launch.JobLauncher;
|
|
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
|
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
|
import org.springframework.batch.core.repository.JobRestartException;
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.WebApplicationType;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import java.util.Properties;
|
|
import java.util.Random;
|
|
|
|
@SpringBootApplication(exclude = {
|
|
HibernateJpaAutoConfiguration.class,
|
|
DataSourceAutoConfiguration.class,
|
|
JpaRepositoriesAutoConfiguration.class
|
|
})
|
|
@EnableAsync
|
|
@EnableScheduling
|
|
@EnableCaching
|
|
@EnableTransactionManagement(proxyTargetClass = true)
|
|
public class BatchApplication {
|
|
private static final Logger logger = LoggerFactory.getLogger(BatchApplication.class);
|
|
|
|
public static void main(String[] args) throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
|
|
SpringApplication app = new SpringApplication(BatchApplication.class);
|
|
app.setWebApplicationType(WebApplicationType.NONE);
|
|
//TODO: 프로그램 실행 처리
|
|
//app.run(BatchApplication.class, args);
|
|
|
|
|
|
ConfigurableApplicationContext ctx = app.run(args);
|
|
JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);
|
|
|
|
logger.info(":::A args Length ::: " + args.length);
|
|
|
|
if (args.length > 0) {
|
|
Job job = ctx.getBean(args[0], Job.class);
|
|
JobParametersBuilder builder = new JobParametersBuilder();
|
|
|
|
builder.addLong("currTime", System.currentTimeMillis());
|
|
|
|
if (args.length > 1) {
|
|
Properties props = StringUtils.splitArrayElementsIntoProperties(args, "=");
|
|
|
|
int idx = 1;
|
|
for (Object okey : props.keySet() ) {
|
|
String key = (String) okey;
|
|
|
|
logger.info("parameter[" + idx + "] :::: " + key + "=" + props.get(key));
|
|
|
|
builder.addString(key, (String) props.get(key));
|
|
idx++;
|
|
}
|
|
}
|
|
|
|
JobExecution jobExecution = jobLauncher.run(job, builder.toJobParameters());
|
|
|
|
if (!jobExecution.getExitStatus().equals(ExitStatus.COMPLETED)) {
|
|
throw new RuntimeException(args[0] + " Job execution failed.");
|
|
}
|
|
} else {
|
|
throw new RuntimeException("배치JOB명은 필수 입니다. EX) java -jar app.jar 배치JOB명");
|
|
}
|
|
|
|
System.exit(0);
|
|
}
|
|
}
|