title: Upload excel file content to mysql using Spring boot and UI
body: <p>I'm trying to upload excel file content to mysql using Spring boot with the help of upload file UI. Need help with that.</p>
  
  <p>But i'm facing Whitelabel Error Page. I've tried couple of things but no luck yet.
  <a href="https://i.stack.imgur.com/PcXG9.png" rel="nofollow noreferrer">Project View</a></p>
  
  <p>ReadFileApplication.java</p>
  
  <pre><code>package com.springboot.file.parsefiles;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.stereotype.Component;
  
  @Configuration
  @EnableAutoConfiguration
  @ComponentScan(basePackages= {"com.springboot.file.parsefiles.controller"})
  @SpringBootApplication
  @Component
  
  public class ReadFileApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(ReadFileApplication.class, args);
  
      }
  }
  
  </code></pre>
  
  <p>ReadFileConrtroller.java</p>
  
  <pre><code>package com.springboot.file.parsefiles.controller;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import com.springboot.file.parsefiles.service.ReadFileService;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RestController;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  
  import com.springboot.file.parsefiles.model.User;
  
  @RestController
  public class ReadFileController 
  {
      @Autowired private ReadFileService readFileService;
  
      @GetMapping(value="/ ")
      public String home(Model model)
      {
          model.addAttribute("user", new User());
          List&lt;User&gt; users = ReadFileService.findAll();
          model.addAttribute("users", users);
          return "view/users";
      }
  
  
      @PostMapping(value="/fileupload")
      public String uploadFile(@ModelAttribute User user, RedirectAttributes redirectAttributes)
      {
          @SuppressWarnings("unused")
          boolean isFlag = readFileService.saveDataFromUploadFile(user.getFile());
          return "redirect:/";
      }
  }
  
  </code></pre>
  
  <p>ReadFileRepository.java</p>
  
  <pre><code>package com.springboot.file.parsefiles.repository;
  
  import org.springframework.data.repository.CrudRepository;
  import org.springframework.stereotype.Repository;
  
  import com.springboot.file.parsefiles.model.User;
  
  @Repository
  public interface ReadFileRepository extends CrudRepository&lt;User, Long&gt;
  {
  
  }
  
  </code></pre>
  
  <p>ReadFileService.java</p>
  
  <pre><code>package com.springboot.file.parsefiles.service;
  
  import java.util.List;
  import org.springframework.web.multipart.MultipartFile;
  import com.springboot.file.parsefiles.model.User;
  
  public interface ReadFileService 
  {
      List&lt;User&gt; findAll = null;
      static List&lt;User&gt; findAll() 
      {
          return null;
      }
      boolean saveDataFromUploadFile(MultipartFile file);
  
  }
  
  </code></pre>
  
  <p>ReadFileServiceImpl.java</p>
  
  <pre><code>package com.springboot.file.parsefiles.service;
  
  import java.util.List;
  
  import com.springboot.file.parsefiles.service.ReadFileService;
  import org.apache.commons.io.FilenameUtils;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  import org.springframework.web.multipart.MultipartFile;
  
  import com.springboot.file.parsefiles.model.User;
  import com.springboot.file.parsefiles.repository.ReadFileRepository;
  
  @Service
  @Transactional
  public class ReadFileServiceImpl implements ReadFileService
  {
      @Autowired private ReadFileRepository readFileRepository;
  
  
      public List&lt;User&gt; findAll()
      {
          return (List&lt;User&gt;) readFileRepository.findAll();
      }
  
  
      @Override
      public boolean saveDataFromUploadFile(MultipartFile file) {
          @SuppressWarnings("unused")
          boolean isFlag = false;
          String extension = FilenameUtils.getExtension(file.getOriginalFilename());
          if(extension.equalsIgnoreCase("json"))
          {
              isFlag = realDataFromJson(file);
          }else if(extension.equalsIgnoreCase("csv"))
          {
              isFlag = realDataFromCsv(file);
          }
          return false;
      }
  
  
      private boolean realDataFromCsv(MultipartFile file) 
      {
          return false;
      }
  
  
      private boolean realDataFromJson(MultipartFile file) 
      {
          return false;
      }
  
  }
  </code></pre>
  
  <p>Applicatiopn.properties</p>
  
  <pre><code>spring.datasource.url = jdbc:mysql://localhost:3306/sampledatabase
  spring.datasource.username = root
  spring.datasource.password = root
  spring.datasource.testWhileIdle = true
  spring.datasource.validationQuery = SELECT 1
  
  spring.jpa.show-sql = true
  
  spring.jpa.hibernate.ddl-auto = update
  
  spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
  
  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
  
  spring.servlet.multipart.max-file-size=100MB
  spring.servlet.multipart.max-request-size=500MB
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field readFileService in com.springboot.file.parsefiles.controller.ReadFileController required a bean of type 'com.springboot.file.parsefiles.service.ReadFileService' that could not be found.
  
  The injection point has the following annotations:
      - @org.springframework.beans.factory.annotation.Autowired(required=true)
  
  
  Action:
  
  Consider defining a bean of type 'com.springboot.file.parsefiles.service.ReadFileService' in your configuration.
  
  </code></pre>