相关文章推荐
道上混的消炎药  ·  Android ...·  2 年前    · 
追风的手套  ·  MySQL ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[class path resource [country.csv]], input=[AA,Aruba]

country.csv

AA,Aruba
BB,Baruba

and here is my ItemReader method

@Bean
    public ItemReader<Country> reader() {
        FlatFileItemReader<Country> reader = new FlatFileItemReader<Country>();
        reader.setResource(new ClassPathResource("country.csv"));
        reader.setLineMapper(new DefaultLineMapper<Country>() {{
            setLineTokenizer(new DelimitedLineTokenizer() {{
                setNames(new String[] { "countryCode", "countryName" });
            setFieldSetMapper(new BeanWrapperFieldSetMapper<Country>() {{
                setTargetType(Country.class);
        return reader;

and Country.java

@Entity
@Table(name="Country")
public class Country  {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, updatable = false)
    Long id;
    @Column(name = "countryCode", nullable = false, updatable = false)
    String countryCode;
    @Column(name = "countryName", nullable = false, updatable = false)
    String countryName;
    public Country(String countryCode, String countryName) {
        this.countryCode = countryCode;
        this.countryName = countryName;
    public Long getId() {
        return id;
    public void setId(Long id) {
        this.id = id;
    public String getCountryCode() {
        return countryCode;
    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    public String getCountryName() {
        return countryName;
    public void setCountryName(String countryName) {
        this.countryName = countryName;
    @Override
    public String toString() {
        return "countryCode: " + countryCode + ", countryName: " + countryName;
                please post full stacktrace; but I will start with empty-ctor for Country and  setters for countryName
– Luca Basso Ricci
                Nov 15, 2015 at 15:06

The problem here is that you are missing a default no-arg constructor in your Country class.

You are using BeanWrapperFieldSetMapper to map a FieldSet to an object. Quoting the setTargetType(type) Javadoc:

An object of this type will be created from its default constructor for every call to mapFieldSet(FieldSet).

As such, you need to add a default constructor and provide the corresponding getter / setter for the properties.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.