- 前面数据库已经连接成功,直接使用默认数据源,实现接口BuildinDatasource以添加内置数据源。
- 完整代码:https://gitee.com/lfw1024/myreport/blob/master/src/main/java/com/ggzn/ureport/datasource/UreportDataSource.java
- 核心代码
@Component
public class UreportDataSource implements BuildinDatasource {
private static final String NAME = "MyDataSource";
private Logger log = LoggerFactory.getLogger(UreportDataSource.class);
@Autowired
private DataSource dataSource;
@Override
public String name() {
return NAME;
}
@Override
public Connection getConnection() {
try {
return dataSource.getConnection();
} catch (SQLException e) {
log.error("Ureport 数据源 获取连接失败!");
e.printStackTrace();
}
return null;
}
}