大家好,又见面了,我是你们的朋友全栈君。
### 1、首先新建一个springboot项目 ###
可以用idea直接新建,也可以在spring-boot官方提供的生成器生成项目,生成地址是:[https://start.spring.io/][https_start.spring.io]
### 2、配置pom.xml ###
org.springframework.boot
spring-boot-starter-jdbc
mysql
mysql-connector-java
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.1
com.syyai.spring.boot
ureport-spring-boot-starter
2.2.9
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
### 3、配置application.yml配置文件 ###
spring:
type: com.alibaba.druid.pool.DruidDataSource
datasource:
url: jdbc:mysql://localhost:3306/ureport?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
main:
allow-bean-definition-overriding: true
logback:
logPath: /ureport/log
level: INFO
server:
port: 8080
### 4、编写config代码类,用于配置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.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
public class UreportConfig implements BuildinDatasource {
@Resource
DataSource dataSource;
private Logger log = LoggerFactory.getLogger(getClass());
@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;
}
}
### 5、启动项目,打开ureport设计页面 ###
访问:http://localhost:8080/ureport/designer
即可打开报表设计页面
[https_start.spring.io]: https://start.spring.io/
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/209967.html原文链接:https://javaforall.cn