Tôi là người mới bắt đầu tại Spring Batch. Tôi đang theo dõi số guide này để tạo HelloWorld cho Spring Batch. Trong lớp học với phương pháp chính khi tôi đã cố gắng để có được Application Context bằng cách sử dụng new ClassPathXmlApplicationContext("...")
, IDE cho thấy một thông báo lỗi nóiCách giải quyết "Loại trừ ngoại lệ BeansException"
Unhandled loại ngoại lệ BeansException
Tôi không thể giải quyết rằng lỗi mặc dù tôi có một khối catch bắt tất cả các loại ngoại lệ. Hãy tham khảo các khối mã bên dưới:
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();
}
}
Sau đó, tôi đã cố gắng để giải quyết nó bằng cách import org.springframework.beans.BeansException;
và cố gắng để bắt BeansException
. Mặc dù lỗi BeansException không được giải quyết đã được giải quyết nhưng một thông báo lỗi khác xuất hiện:
Không ngoại lệ loại BeansException có thể bị ném; một loại ngoại lệ phải là một lớp con của Throwable
Tham khảo các khối mã bên dưới:
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();
}
}
cách chính xác để giải quyết lỗi này là gì?
Lưu ý bổ sung: Tôi không có lớp riêng của tôi có tên là BeansException.
Edit: Stack trace (tiến hành lựa chọn lỗi):
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)
Kiểm tra, làm bạn có một cái gì đó như 'mùa xuân-core-4.2.4.RELEASE .jar' trong đường dẫn lớp học của bạn. Tất nhiên, có phải là phiên bản thực của bạn thay vì '4.2.4'. –
tôi có spring-batch-core-3.0.6.RELEASE.jar; spring-batch-infrastructure-2.2.0.RELEASE.jar; spring-context-4.2.4.RELEASE.jar; spring-beans-4.2.4.RELEASE.jar. Lưu ý: Tôi chỉ có thể nhập 'org.springframework.beans.BeansException' sau khi tôi đã bao gồm spring-beans-4.2.4.RELEASE.jar – karansky
tôi có cần include spring-core-4.2.4.RELEASE.jar không? – karansky