springboot2.x集成ureport2.2.9搭建报表引擎

  • 1、创建springboot项目,修改pom.xml添加相关依赖
  • 2、增加src/main/resources/context.properties
  • 3、修改src/main/resources/application.yml
  • 4、增加com.wongoing.config.ReportConfig.java配置类
  • 5、增加com.wongoing.config.ReportDataSource.java
  • 6、启动com.wongoing.ReportServerApplication.java
  • 7、启动日志
  • 8、打开报表设计器

1、创建springboot项目,修改pom.xml添加相关依赖

pom.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.3</version><relativePath/></parent><groupId>com.wongoing</groupId><artifactId>wgms-report-server</artifactId><version>0.0.1-SNAPSHOT</version><name>wgms-report-server</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 增加常用数据库驱动依赖 --><dependency><groupId>com.microsoft.sqlserver</groupId><artifactId>mssql-jdbc</artifactId><scope>runtime</scope></dependency><dependency><groupId>com.oracle.database.jdbc</groupId><artifactId>ojdbc8</artifactId><scope>runtime</scope></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><scope>runtime</scope></dependency><!--连接池--><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.8</version></dependency><!-- ureport --><dependency><groupId>com.bstek.ureport</groupId><artifactId>ureport2-console</artifactId><version>2.2.9</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

2、增加src/main/resources/context.properties

内容如下:
ureport.fileStoreDir=F:/ureportfiles

3、修改src/main/resources/application.yml

内容如下:

server:port: 9999
####################  项目级数据源配置  ###################
spring:datasource:name: archimedes#generate-unique-name为false时,name的值才会生效generate-unique-name: falseurl: jdbc:mysql://localhost:3306/archimedes?useUnicode=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8username: rootpassword: root@123driver-class-name: com.mysql.cj.jdbc.Driver

4、增加com.wongoing.config.ReportConfig.java配置类

内容如下

package com.wongoing.config;import java.io.IOException;import javax.servlet.Servlet;import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.io.ClassPathResource;import com.bstek.ureport.UReportPropertyPlaceholderConfigurer;
import com.bstek.ureport.console.UReportServlet;import lombok.extern.slf4j.Slf4j;
/*** 功能说明:springboot集成ureport的配置类* 修改说明:* @author zheng* @date 2022-1-21 9:44:57* @version 0.1*/
//导入ureport-console-context.xml文件
@ImportResource("classpath:ureport-console-context.xml")
@Configuration
@Slf4j
public class ReportConfig {/*** 功能说明:注册report的servlet* 修改说明:* @author zheng* @date 2022-1-21 9:43:49* @return*/@Beanpublic ServletRegistrationBean<Servlet> ureport2Servlet() {return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");}/*** 功能说明:加载context.properties配置文件* 修改说明:* @author zheng* @date 2022-1-21 9:44:37* @return* @throws IOException */@Beanpublic UReportPropertyPlaceholderConfigurer UReportPropertyPlaceholderConfigurer() throws IOException {UReportPropertyPlaceholderConfigurer propertyConfigurer = new UReportPropertyPlaceholderConfigurer();propertyConfigurer.setIgnoreUnresolvablePlaceholders(true);org.springframework.core.io.DefaultResourceLoader df = new org.springframework.core.io.DefaultResourceLoader();String userDir = System.getProperty("user.dir");         //获取当前jar运行的路径log.info(userDir);//如果jar所在目录下有config/context.properties,则加载String configFilePath = String.format("file:///%s/%s", userDir, "config/context.properties");log.info(configFilePath);org.springframework.core.io.Resource configResource =  df.getResource(configFilePath);if (configResource.exists()) {propertyConfigurer.setLocation(configResource);return propertyConfigurer;} else {log.warn("configFilePath不存在!");}//如果jar所在目录下有context.properties,则加载String filePath = String.format("file:///%s/%s", userDir, "context.properties");log.info(filePath);org.springframework.core.io.Resource resource =  df.getResource(filePath);if (resource.exists()) {propertyConfigurer.setLocation(resource);return propertyConfigurer;} else {log.warn("filePath不存在!");}//默认加载jar包内的context.properties或如果jar内没有则加载classpath下的context.propertiesClassPathResource pathResource = new ClassPathResource("context.properties");propertyConfigurer.setLocation(pathResource);return propertyConfigurer;}
}

5、增加com.wongoing.config.ReportDataSource.java

内容如下:

package com.wongoing.config;import java.lang.reflect.Field;
import java.sql.Connection;import javax.sql.DataSource;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;import com.alibaba.druid.pool.DruidDataSource;
import com.bstek.ureport.definition.datasource.BuildinDatasource;import lombok.extern.slf4j.Slf4j;/*** 功能说明:ureport默认数据源配置类* 修改说明:* @author zheng* @date 2022-1-21 9:46:09* @version 0.1*/
@Configuration
@Slf4j
public class ReportDataSource implements BuildinDatasource {/*** 注入application.yml中的datasource*/@Autowiredprivate DataSource dataSource;@Overridepublic String name() {// TODO Auto-generated method stubString defaultName ="ReportDataSource"; if (this.dataSource == null) {log.error("注入datasource失败!");return defaultName;} else {if (this.dataSource instanceof DruidDataSource){String name = "ReportDataSource";DruidDataSource dds = ((DruidDataSource)this.dataSource);try {Field[] fields = dds.getClass().getDeclaredFields();for(Field f : fields) {if (f.getName().equals("basicProperties")) {f.setAccessible(true);                  //设置私有属性允许访问Object basicProperties = f.get(dds);Field fieldName = basicProperties.getClass().getDeclaredField("name");if (null != fieldName ) {fieldName.setAccessible(true);       //设置私有属性允许访问Object objNameValue = fieldName.get(basicProperties);if (null != objNameValue) {name = objNameValue.toString();}}break;}}} catch(Exception ex) {log.warn("获取name异常");}if (null == name || "".equals(name)) {return defaultName;} else {return name;}} else {return defaultName; }}}@Overridepublic Connection getConnection() {try {return this.dataSource.getConnection();} catch(Exception ex) {System.out.println(ex.getMessage());return null;}}
}

6、启动com.wongoing.ReportServerApplication.java

内容如下:

package com.wongoing;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class ReportServerApplication {public static void main(String[] args) {SpringApplication.run(ReportServerApplication.class, args);}
}

7、启动日志

.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::                (v2.6.2)2022-01-21 15:28:10.539  INFO 26048 --- [           main] com.wongoing.ReportApplication           : Starting ReportApplication using Java 1.8.0_311 on zhenglibing-pc with PID 26048 (E:\sts-workspace\ureportdemo\target\classes started by zheng in E:\sts-workspace\ureportdemo)
2022-01-21 15:28:10.542  INFO 26048 --- [           main] com.wongoing.ReportApplication           : No active profile set, falling back to default profiles: default
2022-01-21 15:28:11.633  INFO 26048 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method ReportConfig.UReportPropertyPlaceholderConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2022-01-21 15:28:12.103  INFO 26048 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9999 (http)
2022-01-21 15:28:12.115  INFO 26048 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-01-21 15:28:12.115  INFO 26048 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-01-21 15:28:12.266  INFO 26048 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-01-21 15:28:12.266  INFO 26048 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1672 ms
2022-01-21 15:28:12.337  INFO 26048 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2022-01-21 15:28:12.559  INFO 26048 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited_____  __________ __________________ _______ ________ ______________
__   / / /___  __ \___  ____/___  __ \__  __ \___  __ \___  __/__|__ \
_  / / / __  /_/ /__  __/   __  /_/ /_  / / /__  /_/ /__  /   ____/ /
/ /_/ /  _  _, _/ _  /___   _  ____/ / /_/ / _  _, _/ _  /    _  __/
\____/   /_/ |_|  /_____/   /_/      \____/  /_/ |_|  /_/     /____/
........................................................................................................
.  uReport, is a Chinese style report engine licensed under the Apache License 2.0,                    .
.  which is opensource, easy to use,high-performance, with browser-based-designer.                     .
........................................................................................................2022-01-21 15:28:14.063  INFO 26048 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9999 (http) with context path ''
2022-01-21 15:28:14.075  INFO 26048 --- [           main] com.wongoing.ReportApplication           : Started ReportApplication in 4.033 seconds (JVM running for 5.63)

8、打开报表设计器

在浏览器地址栏输入http://localhost:9999/ureport/designer,显示效果如下:

springboot2.x集成ureport2.2.9搭建报表引擎相关推荐

  1. ureport2 + spring boot 搭建

    ureport2使用 ureport2 UReport2是一款基于架构在Spring之上纯Java的高性能报表引擎,通过迭代单元格可以实现任意复杂的中国式报表 在UReport2中,提供了全新的基于网 ...

  2. Springboot2.0集成阿里云RocketMQ

    介绍 RocketMQ是出自阿里巴巴的一款开源消息中间件,在设计上借鉴了Kafka,2017年成为Apache顶级项目,虽然目前社区无法和Kafka比肩,但其历经多次天猫双十一的考验,其性能和稳定是毋 ...

  3. 如何使用活字格搭建报表数据中心系统?

    黑龙江珍宝岛药业股份有限公司(以下简称珍宝岛)是生产高端中药制剂产品的现代化制药企业,是黑龙江民营企业用的标志性单位. 项目背景和需求 1. 企业多系统并存,需要对数据进行整合和规范 通过二十年发展, ...

  4. SpringBoot笔记:SpringBoot2.3集成SpringSession+nginx+redis实现session共享

    文章目录 Spring Session介绍 Redis集成 yml配置 依赖添加 redis存值查看 登录服务器查看redis的值 查询所有"spring:session:"开头的 ...

  5. SpringBoot学习历程(十一):SpringBoot2.X集成mail发送邮件

    SpringBoot学习历程(十一):SpringBoot2.X集成mail发送邮件 前言 1. 引入依赖 2. 设置邮件配置信息 3. 发送邮件 3.1 发送普通文本邮件 3.2 发送HTML格式内 ...

  6. SpringBoot2.x 集成 七牛云对象存储Kodo

    本文主要对SpringBoot2.x集成七牛云对象存储Kodo进行简单总结,其中SpringBoot使用的2.4.5版本. 一.七牛云对象存储Kodo简介 七牛云对象存储Kodo是七牛云提供的高可靠. ...

  7. SpringBoot2.x 集成 FreeMarker

    本文主要对SpringBoot2.x集成FreeMarker及其常用语法进行简单总结,其中SpringBoot使用的2.4.5版本. 一.FreeMarker简介 Apache FreeMarker™ ...

  8. SpringBoot2.x 集成 Thymeleaf

    本文主要对SpringBoot2.x集成Thymeleaf及其常用语法进行简单总结,其中SpringBoot使用的2.4.5版本. 一.Thymeleaf简介 Thymeleaf是面向Web和独立环境 ...

  9. Springboot2.x集成ElasticSearch

    目录 springboot2.x集成es springboot2.x集成es 首先导入我们的pom依赖 <dependency><groupId>org.springframe ...

最新文章

  1. 算法(5) 归并排序
  2. 解决Android中No resource found that matches android:TextAppearance.Material.Widget.Button.Inverse问题
  3. 程序员基本功08异常捕捉的陷阱
  4. python 日期格式校验_python – 如何验证时间格式?
  5. 最佳调度问题(搜索回溯)
  6. 图像阈值中的函数简述
  7. mysql 1129 错误Host is blocked because of many connection errors; unblock with 'mysqladmin flush-host
  8. manage.py和simplejson调用报错解决
  9. Futter基础第6篇: 实现网格布局【GridView、GridView.count、GridView.builder】
  10. 计算机网络综合实践任务书,计算机网络综合实任务书2012-11.doc
  11. 妙启动_十张图带你了解中国国产奶酪巨头——妙可蓝多发展情况
  12. 惠普局域网共享打印机设置_打印机usb转网络?打印机共享怎么设置?怎样设置hp打印机共享器操作方法...
  13. 常见数据结构(二)-树(二叉树,红黑树,B树)
  14. 使用GO实现尚硅谷家庭记账系统
  15. 什么是社会资源?为什么有人会鄙视程序员没有社会资源?
  16. 计算机考试如何使用电脑上的计算器
  17. 小程序开发框架_mpvue(六)卡通照片的实现思路
  18. 【vue3 Api - watchEffect 的讲解 使用】- 侦听响应式数据执行副作用(effect)函数
  19. 一个非常复杂的某考核系统计算考核得分代码层设计
  20. 东南大学计算机专业工程博士,东南大学计算机考博 - 考博 - 小木虫 - 学术 科研 互动社区...

热门文章

  1. 全国计算机等级考试-一级教程excel,全国计算机等级考试教程一级MS Office
  2. 《软件开发工具》要点
  3. 【Unity资源下载】POLYGON Dungeon Realms - Low Poly 3D Art by Synty
  4. o2o项目部署前,阿里云的申请与环境搭建
  5. 计算机网卡与路由器之间线路连接存在故障,win10的系统,有线连接以太网,一直显示的是无法识别的网络,怎么办!!...
  6. 【P06】实用钻石缓冲电路
  7. Win10系统Office 软件图标变白两种解决方法
  8. 中国潜艇上的软件界面
  9. FileZilla网络配置
  10. 智能耳机测试软件,讯飞又一精品,讯飞智能耳机全面评测:商务福音