@[lanyv] SpringBoot+ureport2
//maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--ureport-->
<dependency>
<groupId>com.syyai.spring.boot</groupId>
<artifactId>ureport-spring-boot-starter</artifactId>
<version>2.2.9</version>
</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>
//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