I am new to Spring Batch. I follow this guide to create HelloWorld from Spring Batch. In the class with the main method, when I tried to get the application context using new ClassPathXmlApplicationContext("...") , an error message is displayed in the IDE
Unhandled BeansException
I cannot solve this error, although 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 import org.springframework.beans.BeansException; and tried to catch a BeansException . Although an unhandled BeansException error was resolved, another error message appeared:
An exception of type BeansException is not excluded; the type of exception must be a subclass of the throw
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()); }
What is the correct way to resolve this error?
Additional note: I do not have my own class called BeansException.
Edit: stack trace (continue 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)