Ureport2源码启动

由于本人使用的idea,所以接下来全程使用idea

1. 前期准备

先clone一份源码到本地。 git下载地址 https://gitee.com/youseries/ureport.git

下载的源码文件格式如下:
Ureport2源码启动_第1张图片

2. 导入js项目

idea导入js项目, ureport2-js 文件。 如下:
导入进来后是没有node_modules文件的
需要使用npm install 下载包。
Ureport2源码启动_第2张图片

  • 修改Ureport2-js项目的package.json文件
  1. 在scripts中添加 build及start
  2. 在devDependencies中添加webpack及webpack-cli、webpack-dev-server
  3. 在dependencies 中添加react及react-dom
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack",
    "start": "webpack-dev-server --open"
  },
    "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.6.1",
    "css-loader": "^0.28.11",
    "expose-loader": "^0.7.1",
    "file-loader": "^0.9.0",
    "style-loader": "^0.13.1",
    "uglifyjs-webpack-plugin": "^1.2.4",
    "url-loader": "^0.5.7",
    "webpack": "^4.46.0",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.2"
  },
  "dependencies": {
    "bootbox": "^4.4.0",
    "bootstrap": "^3.3.7",
    "bootstrap-colorpicker": "^2.5.0",
    "chart.js": "^2.7.2",
    "chartjs-plugin-datalabels": "^0.3.0",
    "codemirror": "^5.23.0",
    "completer": "^0.1.3",
    "handsontable": "^0.32.0",
    "jquery": "^3.1.1",
    "jquery-contextmenu": "^2.4.2",
    "node-uuid": "^1.4.7",
    "raphael": "^2.2.7",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "save-svg-as-png": "^1.3.2",
    "undo-manager": "^1.0.5"
  }

以上js项目配置完成。
可以试一下npm run start启动,但是这个项目并不能直接启动, 如需修改的话,修改后可执行npm run build打包
打包后会在源码的Ureoirt2-console项目的src/main/resources/ureport-asserts/js下生成四个js文件。
分别为common.bundle.js、designer.bundle.js、preview.bundle.js、searchform.bundle.js

具体为什么可以参考js项目的webpack.config.js文件中的这句话
在这里插入图片描述

3. 导入后端项目

1. 新建一个SpringBoot项目。
2. 如下步骤所示, 导入Ureport其他四个项目。导入Maven格式

Ureport2源码启动_第3张图片

  • 依次导入Ureport2-console、Ureport2-core、Ureport2-font、Ureport2-parent。
    Ureport2源码启动_第4张图片
  • 修改SpringBoot中的POM文件,引入Ureport依赖
<dependency>
            <groupId>com.bstek.ureportgroupId>
            <artifactId>ureport2-consoleartifactId>
            <version>2.3.0-SNAPSHOTversion>
        dependency>
        <dependency>
            <groupId>com.bstek.ureportgroupId>
            <artifactId>ureport2-coreartifactId>
            <version>2.3.0-SNAPSHOTversion>
        dependency>
        <dependency>
            <groupId>com.bstek.ureportgroupId>
            <artifactId>ureport2-fontartifactId>
            <version>2.0.1version>
        dependency>

        <dependency>
            <groupId>com.oracle.ojdbcgroupId>
            <artifactId>ojdbc8artifactId>
            <version>19.3.0.0version>
        dependency>	
  • 配置文件
server:
  port: 8066
  tomcat:
    max-swallow-size: -1
  servlet:
    context-path:
  address: 0.0.0.0
spring:
  datasource:
    url: jdbc:mysql://192.168.999.999:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    

ureport:
  disableHttpSessionReportCache: false
  #UReport2默认报表存储
  disableFileProvider: false
  fileStoreDir: D:/cshi
  debug: true
  • 新建Ureport配置类,在SpringBoot包中创建config包
package com.tiancai.master.config;

import com.bstek.ureport.definition.datasource.BuildinDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@Component
@Configuration
//不加项目能够启动但是会导致加载数据源报错或加载不了
@ImportResource("classpath:ureport-console-context.xml")
public class UreportDatasource implements BuildinDatasource {

    private static final String NAME = "oracle";
    private Logger log = LoggerFactory.getLogger(UreportDatasource.class);

    @Autowired
    private DataSource dataSource;

    /**
     * 配置ureport的servlet
     * @return
     */
    @Bean
    public ServletRegistrationBean buildUReportServlet() {
        //htreport
        return new ServletRegistrationBean(new UReportServlet(),"/ureport/*");
    }

    /**
     * ds1数据库配置
     */
    @Bean("ds1")
    @ConfigurationProperties(prefix = "spring.datasource.druid.ds1")
    public DataSource ds1Source() {
        return DataSourceBuilder.create().build();
    }

    @Override
    public String name() {
        return NAME;
    }

    @Override
    public Connection getConnection() {
        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            log.error("Ureport 数据源 获取连接失败!");
            e.printStackTrace();
        }
        return null;
    }
    
}
  • SpringBoot 启动类如下:
  • 启动后控制台会输出路径,可以访问了。
public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(MasterApplication.class, args);

        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path")==null?"":env.getProperty("server.servlet.context-path");
        System.out.println("\n----------------------------------------------------------\n\t" +
                "Application UReport is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/ureport/designer\n\t" +
                "----------------------------------------------------------");
    }

游览器输入路径即可启动完成。
Ureport2源码启动_第5张图片

!!!!欢迎讨论。

你可能感兴趣的:(java,javascript,spring,idea)