How to solve "Unhandled exception type BeansException"

Viewed 8475

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)
2 Answers
  1. delete existing jars files form .m2\repository\org\springframework folder.
  2. do clean build by using same version of spring-context.jar, spring-beans.jar and spring-core.jar
Related