当前位置: 首页 > 知识库问答 >
问题:

spring批处理中FlatFileParseException解析类路径资源错误

孙凌
2023-03-14

我想设置csv文件的类路径资源。它位于我的项目资源文件夹中。当设置类路径并运行项目时,我得到的问题是类路径资源的运行时问题

org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[class path resource [result-match-metadata.csv]], input=[id   city    date    player_of_match venue   neutral_venue   team1   team2   toss_winner toss_decision   winner  result  result_margin   eliminator  method  umpire1 umpire2]

result-match-metadata.csv文件存在于我的资源文件夹batchconfig.kt中

package com.nilmani.dashboardipl.data

import com.nilmani.dashboardipl.entity.Match
import org.springframework.batch.core.Job
import org.springframework.batch.core.Step
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory
import org.springframework.batch.core.launch.support.RunIdIncrementer
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider
import org.springframework.batch.item.database.JdbcBatchItemWriter
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder
import org.springframework.batch.item.file.FlatFileItemReader
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.io.ClassPathResource
import javax.sql.DataSource


@Configuration
@EnableBatchProcessing
class BatchConfig {
    @Autowired
    private lateinit var jobBuilderFactory: JobBuilderFactory
    @Autowired
    private lateinit var stepBuilderFactory: StepBuilderFactory
    val FIELD_NAMES = arrayOf(
        "id","city","date","player_of_match","venue","neutral_venue",
        "team1","team2","toss_winner","toss_decision",
        "winner","result","result_margin","eliminator","method","umpire1","umpire2"
    )

    @Bean
    fun reader(): FlatFileItemReader<MatchInput> {
        return FlatFileItemReaderBuilder<MatchInput>()
            .name("MatchItemReader")
            .resource(ClassPathResource("result-match-metadata.csv"))
            .delimited()
            .names(*FIELD_NAMES)
            .fieldSetMapper(object : BeanWrapperFieldSetMapper<MatchInput>() {
                init {
                    setTargetType(MatchInput::class.java)
                }
            })
            .build()
    }
}

如何在批处理配置中设置csv文件路径

共有1个答案

法玮
2023-03-14

正确地找到了资源。该错误意味着第一行不能映射到matchinput的实例。您只需在项目阅读器定义中用FlatFileItemReaderBuilder#LineStoskip(1)跳过标头。

 类似资料:
  • 默认情况下,vue-loader 使用 css-loader 和 Vue 模版编译器自动处理样式和模版文件。在编译过程中,所有的资源路径例如 <img src="...">、background: url(...) 和 @import 会作为模块依赖。 例如,url(./image.png) 会被转换为 require('./image.png'),而 <img src="../image.png

  • 问题内容: 我目前正在开发一个Spring Batch,它可以在第一步中将Excel(.xsls)文件转换为CSV,然后读取CSV,对其进行处理并将其数据存储在数据库中。第一步效果很好。批处理在第二步停止,并发出以下警告:。在我的代码之后: spring-config.xml: 第1步-convertXLSXtoCVS.java: 我在属性文件中提到了文件路径,如下所示: 当我在阅读器定义中从sp

  • 当 Vue Loader 编译单文件组件中的 <template> 块时,它也会将所有遇到的资源 URL 转换为 webpack 模块请求。 例如,下面的模板代码片段: <img src="../image.png"> 将会被编译成为: createElement('img', { attrs: { src: require('../image.png') // 现在这是一个模块的请

  • 我使用的是最新的Spring Batch Admin(1.3.0.Release),并且在我的WAR工件pom文件中包含了'admin-manager'和'admin-resources'。 我的问题是css和图像资源从来没有正确的链接,所以我的管理主页看起来像这样。关于如何配置上下文以正确地包括这些资源,有什么建议吗?

  • 上面是我的程序,错误显示为: 可能的问题是什么?请帮忙,因为我是新来的 我面临着同样的问题,我该如何解决?

  • 我刚刚开始使用springboot,我被这个问题卡住了。没有数据通过控制器。我只想跳转到“index.html”页面,这是一个模板,从bootstrap下载。 这是我的控制器。 index.html. 堆栈跟踪如下。 我想知道我的依赖关系有什么问题吗?