¿Cómo importar de xls a la base de datos mysql usando springbatch?

Estoy intentando crear una API que recibe un archivo .xlsx como entrada. Los datos en el archivo se importan a la base de datos mysql. Había revisado algunos de los tutoriales. Pude hacer que funcionara perfectamente cuando se codificó la ruta del archivo y una vez que se inició el servidor, se ejecuta con éxito. Pero cuando trato de recibir el archivo del usuario y el proceso, obtengo errores. Además, no encuentro muchos recursos para hacer lo mismo.

Abajo está mi código y los errores.

@Controller
public class FileController1 {

    @Autowired 
    private JobLauncher jobLauncher;

    @Autowired 
    private Job importUserJob;

    @Autowired 
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    @Autowired 
    ExcelFileToDatabaseJobConfig excelFileToDatabaseJobConfig;


    @Bean
    ItemReader<StudentDTO> excelStudentReader(@Value("#{jobParameters[fullPathFileName]}") String pathToFile) throws Exception{
        System.out.println("inside excelStudentReader");
        PoiItemReader<StudentDTO> reader = new PoiItemReader<>();
        reader.setLinesToSkip(1);
        reader.setResource(new ClassPathResource(pathToFile));
        //reader.setResource(new UrlResource("file:///D:/joannes/ee.xlsx"));
        reader.setRowMapper(excelRowMapper());
        return reader;
    }
    private RowMapper<StudentDTO> excelRowMapper() {
        System.out.println("inside excelRowMapper");
        BeanWrapperRowMapper<StudentDTO> rowMapper = new BeanWrapperRowMapper<>();
        rowMapper.setTargetType(StudentDTO.class);
        return rowMapper;
    }

    @Bean
    public JdbcBatchItemWriter<StudentDTO> writer(DataSource dataSource) {
        System.out.println("inside writer");
        return new JdbcBatchItemWriterBuilder<StudentDTO>()
                .itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>())
                //.sql("INSERT INTO tbl_item_master (mrp_rate,price,item_code) VALUES (:mrp_rate,:rate,:u_item_code)")
                .sql("update tbl_item_master set mrp_rate=:mrp_rate,price=:rate where item_code=:u_item_code")
                .dataSource(dataSource)
                .build();
    }
    @Bean
    public Job importUserJob(JobCompletionNotificationListener listener, Step step1) {
        System.out.println("inside importUserJob");
        return jobBuilderFactory.get("importUserJob")
                .incrementer(new RunIdIncrementer())
                .listener(listener)
                .flow(step1)
                .end()
                .build();
    }
    @Bean
    public Step step1(JdbcBatchItemWriter<StudentDTO> writer,@Qualifier("excelStudentReader") ItemReader<StudentDTO> importReader)throws Exception {
        System.out.println("inside step1");
        return stepBuilderFactory.get("step1")
                .<StudentDTO, StudentDTO> chunk(3000)
                .reader(importReader)
                //.processor(processor())
                .writer(writer)
                .build();
    }

    @RequestMapping(value = "/echofile", method = RequestMethod.POST, produces = {"application/json"})
    //public @ResponseBody HashMap<String, Object> echoFile(MultipartHttpServletRequest request,
                                    // HttpServletResponse response) throws Exception {
        public @ResponseBody String echoFile(MultipartHttpServletRequest request,
                HttpServletResponse response) throws Exception {

       MultipartFile multipartFile = request.getFile("file");
       /* Long size = multipartFile.getSize();
        String contentType = multipartFile.getContentType();
        InputStream stream = multipartFile.getInputStream();
        byte[] bytes = IOUtils.toByteArray(stream);
        FileUtils.writeByteArrayToFile(new File("D:/joannes/wow.xlsx"), bytes);
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("fileoriginalsize", size);
        map.put("contenttype", contentType);
        map.put("base64", new String(Base64Utils.encode(bytes)));
        */

        String path = new ClassPathResource("/").getURL().getPath();//it's assumed you have a folder called tmpuploads in the resources folder
        File fileToImport = new File(path + multipartFile.getOriginalFilename());
        //filePath = fileToImport.getAbsolutePath();
        OutputStream outputStream = new FileOutputStream(fileToImport);
        IOUtils.copy(multipartFile.getInputStream(), outputStream);
        outputStream.flush();
        outputStream.close();
        //Launch the Batch Job
        JobExecution jobExecution = jobLauncher.run(importUserJob,new JobParametersBuilder()
                .addString("fullPathFileName", fileToImport.getAbsolutePath()).toJobParameters());
        //return map;
        return "something";
    }
}

Error

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fileController1': Unsatisfied dependency expressed through field 'importUserJob'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'importUserJob' defined in class path resource [com/controller/FileController1.class]: Unsatisfied dependency expressed through method 'importUserJob' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'step1' defined in class path resource [com/controller/FileController1.class]: Unsatisfied dependency expressed through method 'step1' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'excelStudentReader' defined in class path resource [com/controller/FileController1.class]: Unsatisfied dependency expressed through method 'excelStudentReader' parameter 0; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?

Tecnologías utilizadas: Springboot, spring-batch-excel, java, mysql, intellij idea, Excel

Respuestas a la pregunta(0)

Su respuesta a la pregunta