您好,欢迎来到五一七教育网。
搜索
您的当前位置:首页java 未处理的异常类型_java – 如何解决“未处理的异常类型BeansException”

java 未处理的异常类型_java – 如何解决“未处理的异常类型BeansException”

来源:五一七教育网

我是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)

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 517ttc.cn 版权所有 赣ICP备2024042791号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务