2017-08-19 21 views
1

私はSpring Batchを把握しようとしています。私はファイルからデータを読み込もうとしますが、例外があります。ここで DateおよびDoubleフィールドのSpring BatchでのFlatFileParseException

1,2012-02-02 14:37:30,112.29369,43.92272 

が読者豆です:ファイルの

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 

    } 

最初の行:これは私のPOJOで、次のように

@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; 
} 

エラーは次のとおりです。

org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[class path resource [data/1.txt]], input=[1,2012-02-02 14:37:30,112.29369,43.92272] 
    at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:184) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE] 
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:88) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE] 
    at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE] 
    at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE] 

...

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 

私はDateについて疑念があり、その目的のためにカスタムエディターを作成しました。その理由は何でしょうか?

+1

答えとして書くことができますか?これは例外の理由です。 – kamaci

答えて

1

NoSuchMethodException: com.gom.tom.simulator.VehicleData.<init>()は、POJOにデフォルトのコンストラクタがないことを意味します。

public class VehicleData { 
    // .... 

    public VehicleData() { 

    } 

    // .... 
} 
関連する問題