Java 日期和双字段在春季批处理时发生FlatFileParseException
我在试着弄清楚春季的批次。我试图从文件中读取数据,但出现异常。这是我的POJO:Java 日期和双字段在春季批处理时发生FlatFileParseException,java,spring,spring-batch,Java,Spring,Spring Batch,我在试着弄清楚春季的批次。我试图从文件中读取数据,但出现异常。这是我的POJO: public class VehicleData { private Long vehicleId; private Date timestamp; private Double latitude; private Double longitude; public VehicleData(Long vehicleId, Date timestamp, Double lat
public class VehicleData {
private Long vehicleId;
private Date timestamp;
private Double latitude;
private Double longitude;
public VehicleData(Long vehicleId, Date timestamp, Double latitude, Double longitude) {
this.vehicleId = vehicleId;
this.timestamp = timestamp;
this.latitude = latitude;
this.longitude = longitude;
}
//getters and setters
}
文件的第一行:
1,2012-02-02 14:37:30,112.29369,43.92272
以下是ReaderBean:
@Bean
public FlatFileItemReader<VehicleData> reader() {
FlatFileItemReader<VehicleData> reader = new FlatFileItemReader<>();
reader.setResource(new ClassPathResource("data/1.txt"));
reader.setLineMapper(new DefaultLineMapper<VehicleData>() {{
setLineTokenizer(new DelimitedLineTokenizer() {{
setNames(new String[]{"vehicleId", "timestamp", "latitude", "longitude"});
}});
setFieldSetMapper(new BeanWrapperFieldSetMapper<VehicleData>() {{
setTargetType(VehicleData.class);
setCustomEditors(Collections.singletonMap(Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), false)));
}});
}});
return reader;
}
由以下原因引起:java.lang.reflect.UndeclaredThrowableException:null
在org.springframework.util.ReflectionUtils.HandlerReflectionException(ReflectionUtils.java:285)~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.getBean(BeanWrapperFieldSetMapper.java:236)~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
在org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.mapFieldSet(BeanWrapperFieldSetMapper.java:185)~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
在org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:43)~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
在org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:180)~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
... 省略51个公共帧
原因:java.lang.InstanceException:com.gom.tom.simulator.VehicleData
在java.lang.Class.newInstance(Class.java:427)~[na:1.8.0_102]
在org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.getBean(BeanWrapperFieldSetMapper.java:233)~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
... 省略54个公共框架
原因:java.lang.NoSuchMethodException:com.gom.tom.simulator.VehicleData。()
在java.lang.Class.getConstructor0(Class.java:3082)~[na:1.8.0\u 102]
在java.lang.Class.newInstance(Class.java:412)~[na:1.8.0_102]
... 省略55个公共框架
我对日期表示怀疑,并为此编写了一个自定义编辑器。原因可能是什么?
NoSuchMethodException:com.gom.tom.simulator.VehicleData。(
表示POJO中缺少默认构造函数
public class VehicleData {
// ....
public VehicleData() {
}
// ....
}
你能写下来作为回答吗?这是例外的原因。
Caused by: java.lang.reflect.UndeclaredThrowableException: null
at org.springframework.util.ReflectionUtils.handleReflectionException(ReflectionUtils.java:285) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.getBean(BeanWrapperFieldSetMapper.java:236) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.mapFieldSet(BeanWrapperFieldSetMapper.java:185) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:43) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:180) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
... 51 common frames omitted
Caused by: java.lang.InstantiationException: com.gom.tom.simulator.VehicleData
at java.lang.Class.newInstance(Class.java:427) ~[na:1.8.0_102]
at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.getBean(BeanWrapperFieldSetMapper.java:233) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
... 54 common frames omitted
Caused by: java.lang.NoSuchMethodException: com.gom.tom.simulator.VehicleData.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_102]
at java.lang.Class.newInstance(Class.java:412) ~[na:1.8.0_102]
... 55 common frames omitted
public class VehicleData {
// ....
public VehicleData() {
}
// ....
}