SpringBoot整合Ureport2实现报表完整版

@[lanyv] SpringBoot+ureport2

//maven依赖
		
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            com.syyai.spring.boot
            ureport-spring-boot-starter
            2.2.9
        
        
            mysql
            mysql-connector-java
            5.1.46
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        




//ureport2配置类
import com.bstek.ureport.console.UReportServlet;
import com.bstek.ureport.definition.datasource.BuildinDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
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 javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@ImportResource("classpath:ureport-console-context.xml")//不加项目能够启动但是会导致加载数据源报错或加载不了
@Configuration
@EnableAutoConfiguration
public class UreportConfig implements BuildinDatasource {
    @Resource
    DataSource dataSource;
    private Logger log = LoggerFactory.getLogger(getClass());

    @Bean //定义ureport的启动servlet
    public ServletRegistrationBean buildUreportServlet(){
        return new ServletRegistrationBean(new UReportServlet(),"/ureport/*");
    }

    @Override
    public String name() {
        return "System";
    }

    @Override
    public Connection getConnection() {
        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            log.error("Ureport 数据源 获取连接失败!");
            e.printStackTrace();
        }
        return null;
    }

}


     yml配置
 spring:
    datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: 1234
        url: jdbc:mysql://127.0.0.1:3306/test?&serverTimezone=Asia/Shanghai
        username: root
    main:
        allow-bean-definition-overriding: true
server:
    port: 8090

UReport2 配置文件 在类路径下建一个ureport.properties 配置报表保存路径

``
ureport.disableHttpSessionReportCache=false

#UReport2默认报表存储
ureport.disableFileProvider=false
ureport.fileStoreDir=d:/ureportfiles
ureport.debug=true

访问路径,连接内置数据源

SpringBoot整合Ureport2实现报表完整版_第1张图片

你可能感兴趣的:(springboot,spring,boot,java)