I am a beginner at Spring Batch. I am following this guide to create a HelloWorld of Spring Batch. In the class with main method when I was trying to get Application Context by using new ClassPathXmlApplicationContext("..."), the IDE shows an error message saying
Unhandled exception type BeansException
I cannot solve that error even though I have a catch block that catches all types of exceptions. Refer to the code block below:
public static void main(String args[]) {
try {
//error message appears here
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("simpleJob.xml");
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("Date", "12/02/2011");
jobLauncher.run(job, builder.toJobParameters());
JobExecution jobExecution = jobRepository.getLastJobExecution(job.getName(), builder.toJobParameters());
System.out.println(jobExecution.toString());
}
catch(Exception e) {
e.printStackTrace();
}
}
Then, I tried to solve it by import org.springframework.beans.BeansException; and tried to catch BeansException. Although the unhandled BeansException error was solved but another error message appeared:
No exception of type BeansException can be thrown; an exception type must be a subclass of throwable
Refer to the code block below:
public static void main(String args[]) {
try {
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("simpleJob.xml");
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("Date", "12/02/2011");
jobLauncher.run(job, builder.toJobParameters());
JobExecution jobExecution = jobRepository.getLastJobExecution(job.getName(), builder.toJobParameters());
System.out.println(jobExecution.toString());
}
//error message appears here
catch(BeansException e) {
//do something
}
catch(Exception e) {
e.printStackTrace();
}
}
What is the correct way to solve this error?
Additional note: I do not have my own class named BeansException.
Edit: Stack trace (proceed with error option):
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No exception of type BeansException can be thrown; an exception type must be a subclass of Throwable
at SpringBatchHelloWorld.BatchLauncher.main(BatchLauncher.java:29)