[is it possible to access two spring batch jobs from single servlet?]
[i have two jobs 1. file to two files 2. two files to two tables. Both batch jobs are individually working fine but when i call from single servlet then it is trowing run time error. ]
can you please help on this
web.xml
-----------
[<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/CustomCompositeItemWriterJob.xml,
/WEB-INF/FilesToTablesJob.xml
</param-value>
</context-param>]
uploadservlet.java
---------------------
[PrintWriter out = response.getWriter();
JobExecution status1 =null;
JobExecution status2 =null;
Date date = new Date();
ServletContext context = getServletContext();
WebApplicationContext applicationContext1 = WebApplicationContextUtils.getWebApplicationContex t(context);
WebApplicationContext applicationContext2 = WebApplicationContextUtils.getWebApplicationContex t(context);
JobLauncher launcher1 = (JobLauncher ) applicationContext1.getBean("jobLauncher");
JobLauncher launcher2 = (JobLauncher ) applicationContext2.getBean("jobLauncher");
Job job1 = (Job ) applicationContext1.getBean("singleInputMultipleOu tputsJob");
JobParameters jobParameters1= new JobParametersBuilder().addDate("schedule.time", date).toJobParameters();
try
{
status1 = launcher1.run((org.springframework.batch.core.Job) job1,jobParameters1);
}
catch(Exception e1)
{
out.println(e1);
}
response.setContentType("text/html");
out.print(status1.getExecutionContext());
out.println(status1.getExitStatus());
String s="Hello, spring batch!";
String s1="hp";
String s2="spring batch! done";
Job job2 = (Job ) applicationContext2.getBean("filesToTablesJob");
JobParameters jobParameters2= new JobParametersBuilder().addDate("schedule.time", date).toJobParameters();
try {
status2 = launcher2.run((org.springframework.batch.core.Job) job2,jobParameters2);
} catch(Exception e2)
{
out.println(e2);
}
out.print(status2.getExecutionContext());
out.println(status2.getExitStatus());
out.flush();]


Reply With Quote
!!!