ureport2学习笔记一:springboot2集成ureport2 ,使用内置方式配置数据源,并解决配置数据时的碰到的问题

UReport2是一款纯Java的高性能报表引擎。 其优点在于:是开源的,基于Apache-2.0开源协议;其次,在项目中直接集成网页端报表设计器,灵活、方便、易维护和管理;另外,可以实现任意复杂的中国式报表。

步骤一:新建一个springboot2的Maven工程项目,并导入UReport2的依赖。配置如下:
  
        org.springframework.boot
        spring-boot-starter-parent
        2.1.7.RELEASE
       
   


            org.springframework.boot
            spring-boot-starter-web
       

       
            org.springframework.boot
            spring-boot-devtools
            runtime
            true
       

       
            org.projectlombok
            lombok
            true
       

       
            org.springframework.boot
            spring-boot-starter-test
            test
       

    
       
            com.alibaba
            druid-spring-boot-starter
            1.1.10
       

       
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.0
       

       
            mysql
            mysql-connector-java
            runtime
       

     
       
            com.syyai.spring.boot
            ureport-spring-boot-starter
            2.2.9
       

步骤二:创建UReport配置文件UreportConfig.java

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

    @Resource
    DataSource dataSource;

    @Bean //定义ureport的启动servlet
    @SuppressWarnings("unchecked")
    public ServletRegistrationBean ureportServlet(){
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new UReportServlet());
        servletRegistrationBean.addUrlMappings("/ureport/*");
        return servletRegistrationBean;
    }
    @Override
    public String name() {
        return "myUReportDatasource";
    }

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

至此 springboot2集成ureport2 初步完成,但是在配置数据源时还有问题需要解决。
问题一:此时有可能项目启动不了,并报错Configuration problem: Failed to import bean definitions from URL location [classpath:ureport-core-context.xml]

解决办法:在springboot配置文件application.yml或application.properties 中加上配置
spring.main.allow-bean-definition-overriding=true

问题二:启动项目,配置使用数据源时,加载不了数据 同时后台报错 com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone

解决办法:在数据源url后加上&serverTimezone=UTC配置

 

 

 

你可能感兴趣的:(ureport2学习笔记一:springboot2集成ureport2 ,使用内置方式配置数据源,并解决配置数据时的碰到的问题)