UReport2集成SpringBoot-基础配置
1. 引入maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.bstek.ureport</groupId>
<artifactId>ureport2-console</artifactId>
<version>2.2.8</version><!--2.2.5升级到2.2.8图表才可以 byliuyongling-->
</dependency>
2. 注入UReport2 需要使用到的Servlet,并引入配置文件
@SpringBootApplication
@ImportResource("classpath:ureport-console-context.xml")
public class Ureport2DemoApplication {
public static void main(String[] args) {
SpringApplication.run(Ureport2DemoApplication.class, args);
}
@Bean
public ServletRegistrationBean<UReportServlet> buildUreportServlet(){
return new ServletRegistrationBean<UReportServlet>(new UReportServlet(), "/ureport/*");
}
}
3. 配置application.yml
server:
port: 8081
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: test
password: test
driver-class-name: com.mysql.jdbc.Driver
4. 修改报表默认路径
在resource下创建ureport.properties
,文件内容如下
ureport.disableHttpSessionReportCache=true
ureport.disableFileProvider=false
ureport.fileStoreDir=d:/ureport2files
ureport.debug=true
5. 启动SpringBoot项目
访问http://localhost:8081/ureport/designer
,出现如下界面则配置成功