Excel File – Download from SpringBoot RestAPI + Apache POI + MySQL


In the tutorial, we show you how to create a SpringBoot RestAPIs application that uses Spring JPA to get data from MySQL records and uses Apache POI library to write data to a Excel file.

Related posts:
Java – How to read/write Excel file with Apache POI
How to use Spring JPA MySQL | Spring Boot
SpringBoot – Upload/Download MultipartFile to FileSystem – Bootstrap 4 + JQuery Ajax


– Spring Boot – 2.0.6.RELEASE
– Spring JPA
– Apache POI


Project Structure ->


Create SpringBoot project

Use SpringToolSuite to create a SpringBoot project with below dependencies:

Customer Model

Customer.java ->

JPA Customer Repository

CustomerRepository.java ->

Implement Excel Generator

ExcelGenerator.java ->

Implement RestAPI Controller

CustomerExcelDownloadRestAPI.java ->

Implement Download View

– Create ViewController.java ->

– Create .html view home.html ->

Initial Customers

– In main class, we use CommandLineRunner to init Customer’s records:

Database Configuration

application.properties ->

Run & Check Results

Run the SpringBoot project,

-> MySQL’s records:


-> Excel Downloaded File:






By grokonez | October 18, 2018.

Related Posts

7 thoughts on “Excel File – Download from SpringBoot RestAPI + Apache POI + MySQL”

  1. You should set Content-Type in order to have a valid mime Type.
    For example
    headers.add(“Content-Type”, “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”);

  2. I tried this, but getting error. Actually I have configured plsql db in application.properties seems profile is not activated.
    I want to pull the record from plsql and download as excel. Please help me.

    INFO: No Active profile set, falling back to default profiles: default
    INFO: Refreshing org.springframework.boot.context.embedded.annotationConfigEmbeddedWebapplicationcontect@66fd8833:startupdate ; root of context hierarchy
    WARN: Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException:Failed to parse configuration class [com.dataextract.SpringJpaExcelDownloaderApplication]; nested exception is java.io.FileNotFoundException: Class path resource[application.properties] cannot be opened because it does not exist.
    ERROR: Destroy method on bean withname ‘org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory’ threw an exception.

    I am new to spring boot. i want to finish this for my organization. Please help me.

Got Something To Say:

Your email address will not be published. Required fields are marked *