Personal learning series - Spring Boot integration UReport2

It is always necessary to generate various reports in work, which is very troublesome. Recently, I found a UReport2, which is said to be able to realize complex Chinese style reports. I'm a little excited...

1. Create a new springboot project

1.1 pom.xml





1.2 application.yml

  port: 8888
# Database link data source configuration
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://IP address: 3306 / database name? useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&serverTimezone=GMT%2B8
    username: Database user name
    password: Database password

1.3 write a config code class to configure UReport2

 * springboot Entity class configuration
 * context.xml Configuration file for UReport2
 * @author zhouzhaodong
public class BeanConfig {

    public ServletRegistrationBean<Servlet> ureport2Servlet() {
        return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");


1.4 create a new configuration file context for UReport2 xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    <import resource="classpath:ureport-console-context.xml"/>
    <!-- Import profile -->
    <bean id="propertyConfigurer" parent="ureport.props">
        <property name="location" value=""/>


1.5 create a new context properties

Here I mainly define the default file system based report storage directory provided in UReport2:

# Used to define the default file system based report storage directory provided in UReport2

It should be noted here that we set the report to be stored under the ureportfiles folder. This folder needs to be created manually, otherwise it cannot be saved...

1.6 the built-in data source needs to be defined here

It should be noted that there are three ways to connect data sources:

  1. To directly connect to the database is to add the driver Jar package of the corresponding database in the classpath of the project, and then configure the data source connection information in the pop-up window, as shown in the following figure:

  1. Spring Bean: select a Bean defined in the spring context as the data source, click the icon, and enter the name of the data source and the ID of the Bean to be used in the pop-up window, as shown in the following figure:

After saving, you can add a specific dataset under this data source by right clicking the data source, selecting Add dataset in the pop-up menu, and defining the dataset name, corresponding method name and return object type in the pop-up window, as shown in the following figure:

  1. By implementing com bstek. ureport. definition. datasource. Built in data source provided by buildindatasource interface:

Previously in application The database information is configured in YML.

 * Ureport data source
 * @author zhouzhaodong

public class UreportDataSource implements BuildinDatasource {
    private static final String NAME = "MyDataSource";
    private final Logger log = LoggerFactory.getLogger(UreportDataSource.class);

    private DataSource dataSource;

     * Data source name
    public String name() {
        return NAME;

     * Get connection
    public Connection getConnection() {
        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            log.error("Ureport Failed to get connection from data source!");
        return null;


2. Test

2.1 start up project

Successful printing of console information means:

2.2 access http://localhost:8888/ureport/designer

The access address is obtained according to the configuration file:

2.3 setting data source

After clicking OK, the data source will be finished. Of course, those complex data queries can be done by yourself!

2.4 setting report

2.5 saving reports

2.6 various types of download links

Personal blog address

GitHub source address

Tags: Spring Boot

Posted by skoobi on Sun, 15 May 2022 22:28:19 +0300