How to solve "Unhandled BeansException"

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()); } //error message appears here catch(BeansException e) { //do something } catch(Exception e) { e.printStackTrace(); } } 

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) 
+6
source share
2 answers

Thanks to Ken Bikov for comments on this question, I was able to solve this problem, and I formulated this solution to officially answer this question. Loans must be provided to Ken Bekov.

Solution: The problem was related to another version of the .jar files included in the build path. The .jar files to be included are: spring-context-4.2.5.RELEASE.jar , spring-beans-4.2.5.RELEASE.jar and spring-core-4.2.5.RELEASE.jar (note the same version number is 4.2.5).

As for spring-batch-core-3.0.6.RELEASE.jar , spring-batch-infrastructure-3.0.6.RELEASE.jar and others, they do not have to have the same version number (4.2.5).

After the correct .jar files were included, even the error message "Unhandled exception of type BeansException" for new ClassPathXmlApplicationContext("...");

+8
source
  • delete existing jars..m2 \ repository \ org \ springframework files.
  • do a clean build using the same version of spring -context.jar, spring - beans.jar and spring -core.jar
0
source

All Articles