Rest in Jasperreports Server Simple Svn Versioning and Continuous Integration
Welcome readers, in this tutorial, we will show how to use JasperReports with spring boot framework.
1. Introduction
- Spring boot is a module that provides rapid application development feature to the spring framework including auto-configuration, standalone-code, and production-ready code
- It creates applications that are packaged as jar and are directly started using embedded servlet container (such as Tomcat, Jetty or Undertow). Thus, no need to deploy the war files
- It simplifies the maven configuration by providing the starter template and helps to resolve the dependency conflicts. It automatically identifies the required dependencies and imports them in the application
- It helps in removing the boilerplate code, extra annotations, and xml configurations
- It provides a powerful batch processing and manages the rest endpoints
- It provides an efficient jpa-starter library to effectively connect the application with the relational databases
- It offers a Microservice architecture and cloud configuration that manages all the application related configuration properties in a centralized manner.
1.1 JasperReports
JasperReports is an open-source reporting library. It is used to prepare reports in various formats such as PDF, HTML, XLS or CSV's. This library creates page-oriented ready-to-print documents in a simple manner. The following flow chart illustrates the creation of reports.
In this tutorial, we will create a spring boot application that loads the sample employee data and creates a pdf report using the jasper-report library. To follow this concept, let us open the eclipse ide and implement this tutorial. But before going any further I'm assuming that readers are aware of the concepts of creating and running a basic spring boot application.
2. JasperReports with Spring Boot
Here is a systematic guide for implementing this tutorial.
2.1 Tools Used
We are using Eclipse Kepler SR2, JDK 8, and Maven.
2.2 Project Structure
In case you're confused about where you should create the corresponding files or folder, let us review the project structure of the spring boot application.
Let us start building the application!
3. Creating a Springboot application
Below are the steps involved in developing the application.
3.1 Maven Dependency
Here, we specify the dependency for the spring boot, free marker, and jasper-reports. Maven will automatically resolve the other dependencies. The updated file will have the following code.
pom.xml
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
3.2 Application Properties
Create a new properties file at the location: SpringbootJasperreports/src/main/resources/ and add the following code to it.
application.properties
| 1 2 3 4 5 6 7 | |
3.3 Report Template File
Create a report template file at the location SpringbootJasperreports/src/main/resources/ and add the following code to it. A .jrxml file contains the template definition in an XML format i.e. this JasperReport template file includes design elements such as text-fields, charts, parameters, variables and the report layout. In this template, we have four fields that are mapped to the elements of the data source bean. It also has the text-field element that is filled with dynamic data from the application.
report.jrxml
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
3.4 Freemarker Template File
Create a freemarker template file at the location SpringbootJasperreports/src/main/resources/templates/ and add the following code to it. This file will be shown to the users on the application startup.
welcome.ftl
3.5 Java Classes
Let us write all the java classes involved in this application.
3.5.1 Implementation/Main class
Add the following code to the main class to bootstrap the application from the main method. Always remember, the entry point of the spring boot application is the class containing @SpringBootApplication annotation and the static main method.
Jasperreports.java
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 | |
3.5.2 Model class
Add the following code to the Employee model class.
Employee.java
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
3.5.3 Service class
Add the following code to the service class where we will prepare the dummy data for an employee.
EmployeeServiceImpl.java
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
3.5.4 Controller class
Add the following code to the controller class designed to handle the incoming requests. The class exposes two methods to display the welcome page of the application and generates the employee report.
EmployeeController.java
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
4. Run the Application
To execute the application, right-click on the Application.java class, Run As -> Java Application.
5. Project Demo
Developers can hit the below URL that will open the index of the application. On the index page, the application has the 'Generated Pdf' button that will generate the employee report as shown in the below figure.
http://localhost:10091/api/welcome
That is all for this tutorial and I hope the article served you whatever you were looking for. Happy Learning and do not forget to share!
6. Conclusion
In this section, developers learned how to use JasperReports with a spring boot application. Developers can download the sample application as an Eclipse project in the Downloads section.
7. Download the Eclipse Project
This was an example of using JasperReports with a Spring boot application.
ramoslarmincess1998.blogspot.com
Source: https://examples.javacodegeeks.com/jasperreports-with-spring-boot/
Post a Comment for "Rest in Jasperreports Server Simple Svn Versioning and Continuous Integration"