Sping Excel REST API with JasperReports
Java, Maven, JasperReports, REST, Spring Boot
JasperReports is a Java library, and it is meant for Java developers who need to add reporting to their applications.
Introduction
In this post, we will create an excel report that is exposed over RESTful endpoint using Spring Boot. In a previous post we looked at how to expose Jasper PDF over REST.
Prerequisites
Project Structure
At the end of this guide our folder structure will look similar to the following:
.
|__src/
| |__main/
| | |__java/
| | | |__com/
| | | | |__juliuskrah/
| | | | | |__jasper/
| | | | | | |__Application.java
| | | | | | |__ApplicationProperties.java
| | | | | | |__report/
| | | | | | | |__JasperReportsService.java
| | | | | | | |__ReportService.java
| | | | | | |__storage/
| | | | | | | |__FileSystemStorageService.java
| | | | | | | |__StorageException.java
| | | | | | | |__StorageFileNotFoundException.java
| | | | | | | |__StorageService.java
| | | | | | |__web/
| | | | | | | |__rest/
| | | | | | | | |__ApplicationResource.java
| | |__resources/
| | | |__reports/
| | | | |__pdf_rest_resource.jrxml
| | | | |__pdf_rest.jrxml
| | | |__application.yaml
| | | |__cherry.png
| | | |__logo.png
|__pom.xml
How to complete this guide
To complete this guide, download (zip| tar.gz) and unzip the source repository for this guide.
Create Excel Report
Let us start by implementing a solution to generate excel in JasperReports:
file:
src/main/java/com/juliuskrah/jasper/report/JasperReportsService.java
Render the Excel REST Endpoint
We will create the REST endpoint:
file:
src/main/java/com/juliuskrah/jasper/web/rest/ApplicationResource.java
Now navigate to http://localhost:8080/:username to view your report.
Conclusion
In this post we learned how to generate Excel with JasperReports and serve it over HTTP with Spring Boot. As usual you can find the full example to this guide in the github repository. Until the next post, keep doing cool things .