我是Spring Batch的初学者.我正在关注这个guide以创建一个Spring Batch的HelloWorld.在使用main方法的类中,当我尝试使用新的ClassPathXmlApplicationContext(“…”)来获取Application Context时,IDE会显示一条错误消息
Unhandled exception type BeansException
即使我有一个捕获所有类型的异常的catch块,我也无法解决该错误.请参阅下面的代码块:
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();
}
}
然后,我尝试通过import org.springframework.beans.BeansException解决它;并试图捕获BeansException.虽然未处理的BeansException错误已解决,但出现了另一条错误消息:
No exception of type BeansException can be thrown; an exception type
must be a subclass of throwable
请参阅下面的代码块:
public static void main(String args[]) {
try {
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("simpleJob.xml");
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("Date",builder.toJobParameters());
System.out.println(jobExecution.toString());
}
//error message appears here
catch(BeansException e) {
//do something
}
catch(Exception e) {
e.printStackTrace();
}
}
解决此错误的正确方法是什么?
附加说明:我没有自己的名为BeansException的类.
编辑:堆栈跟踪(继续错误选项):
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)