springCloud通过网关访问ureport

一、ureport及springCloud介绍

UReport2是一款基于架构在Spring之上纯Java的高性能报表引擎,通过迭代单元格可以实现任意复杂的中国式报表。
问题在于如果你用了springCloud,原生的ureport是不能通过网关(zuul)访问的,那么这个应用就需要单独部署,其次不经过网关(zuul),权限问题也就比较尴尬,所以这篇文章应运而生.。
注意:我的版本是根据2.26版本修改的,别的版本可能需要微调
修改源码的方式,建议大家把源码拖出来,加到自己项目里,如下:
springCloud通过网关访问ureport_第1张图片
这样加载的时候会先读取你项目里面的文件,然后才是jar包里面的文件;这样你的文件就覆盖了jar的文件,别人从maven下的包只要版本和你一致,就不会有问题,
如果你需要升级ureport版本,有问题可以在项目里的源码内针对性修改;
我也上传了我修改的部分,不包括配置文件,至于积分象征性给了1分,链接如下:
https://download.csdn.net/download/qq_36126934/10597720

二、通过网关访问ureport的配置文件

首先网关(zuul)默认不配置的话,如果网关的端口是8080,集成ureport的项目(我的名字是reportform)的端口是8100
默认访问地址
http://localhost:8100/ureport/designer
通过网关的访问地址应该是:
http://localhost:8080/reportform/ureport/designer

闲话不多说开始讲解配置:
先在application.properties加个配置

spring.reportform.entity.name=reportform

这里的配置可以考虑和eurekaserver里注册的服务名service_name用同一个,例如:

spring.application.name=reportform

然后在ReportFormConfig里面加上读取配置
com.strike.reportform.entity.ReportFormConfig

package com.strike.reportform.entity;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component
@PropertySource("classpath:application.properties")
@ConfigurationProperties(prefix = "spring.reportform.entity")
public class ReportFormConfig {
    private String name;
    public String getName() {
        return "/"+name;
    }
    public void setName(String name) {
        this.name = name;
    }

}

三、源码修改(一)

修改com.bstek.ureport.console.designer.DesignerServletAction

注入ReportFormConfig

    @Autowired
    private ReportFormConfig reportFormConfig;
// 源码:context.put("contextPath", req.getContextPath());
//改成下面这样
context.put("contextPath", req.getContextPath()+reportFormConfig.getName());

四、源码修改(二)

修改com.bstek.ureport.console.designer.SearchFormDesignerAction
注入ReportFormConfig

    @Autowired
    private ReportFormConfig reportFormConfig;
// 源码:context.put("contextPath", req.getContextPath());
//改成下面这样
context.put("contextPath", req.getContextPath()+reportFormConfig.getName());

五、源码修改(三)

修改com.bstek.ureport.console.designer.HtmlPreviewServletAction
注入ReportFormConfig

    @Autowired
    private ReportFormConfig reportFormConfig;
// 源码:context.put("contextPath", req.getContextPath());
//改成下面这样
context.put("contextPath", req.getContextPath()+reportFormConfig.getName());
//源码htmlReport=exportManager.exportHtml(file,req.getContextPath(),parameters,index);
//改成下面这样
htmlReport = exportManager.exportHtml(file, getCorrectName(req.getContextPath()), parameters, index);
//源码htmlReport=exportManager.exportHtml(file,req.getContextPath(),parameters);
//改成下面这样
htmlReport = exportManager.exportHtml(file, getCorrectName(req.getContextPath()), parameters);

六、大功告成,访问吧

首先网关(zuul)默认不配置的话,如果网关的端口是8080,集成ureport的项目(我的名字是reportform)的端口是8100
默认访问地址
http://localhost:8100/ureport/designer
通过网关的访问地址应该是:
http://localhost:8080/reportform/ureport/designer
现在就可以通过网关来访问了,但是问题是只能通过网关访问;

你可能感兴趣的:(ureport)