spring boot通过连接池的方式连接时序库IotDB

1、maven依赖

复制代码
<dependency>
            <groupId>org.apache.iotdb</groupId>
            <artifactId>iotdb-session</artifactId>
            <version>1.3.2</version>
        </dependency>

2、配置文件

复制代码
iotdb:
  server:
    url: localhost
    port: 6667
    name: root
    pwd: root
    maxSize: 100
    dataBaseName: root.ln

3、定义配置文件

复制代码
@Data
@Component("IotDbProperties")
@Configuration
public class IotDbProperties {
    @Value("${iotdb.server.url}")
    private String url;
    @Value("${iotdb.server.port}")
    private Integer port;
    @Value("${iotdb.server.name}")
    private String name;
    @Value("${iotdb.server.pwd}")
    private String pwd;
    @Value("${iotdb.server.maxSize}")
    private Integer maxSize;
    @Value("${iotdb.server.dataBaseName}")
    private String iotDataBaseName;

    @Bean("sessionPool")
    public ISessionPool getSessionPool() {
        return new SessionPool(this.url, this.port, this.name, this.pwd, this.maxSize);
    }
}

4、在服务层使用

通过sessionPool直接调用方法

复制代码
@Service
@Slf4j
public class IotDbServiceImpl implements IIotDbService {

    @Resource
    private ISessionPool sessionPool;

    @Value("${iotdb.server.dataBaseName}")
    private String iotDataBaseName;

注意:如果需要用到:SessionDataSetWrapper sessionDataSetWrapper查询的话,则必须调用

复制代码
sessionDataSetWrapper.close();

或者使用 try-with-resources会进行自动关闭

相关推荐
亚力山大抵10 分钟前
实验六-使用PyMySQL数据存储的Flask登录系统-实验七-集成Flask-SocketIO的实时通信系统
后端·python·flask
超级小忍20 分钟前
Spring Boot 中常用的工具类库及其使用示例(完整版)
spring boot·后端
程序员张333 分钟前
SQL分析与打印-p6spy组件
spring boot·sql·mybatis·mybatisplus·p6spy
CHENWENFEIc1 小时前
SpringBoot论坛系统安全测试实战报告
spring boot·后端·程序人生·spring·系统安全·安全测试
重庆小透明2 小时前
力扣刷题记录【1】146.LRU缓存
java·后端·学习·算法·leetcode·缓存
博观而约取2 小时前
Django 数据迁移全解析:makemigrations & migrate 常见错误与解决方案
后端·python·django
寻月隐君3 小时前
Rust 异步编程实践:从 Tokio 基础到阻塞任务处理模式
后端·rust·github
GO兔3 小时前
开篇:GORM入门——Go语言的ORM王者
开发语言·后端·golang·go
Sincerelyplz3 小时前
【Temproal】快速了解Temproal的核心概念以及使用
笔记·后端·开源
爱上语文3 小时前
Redis基础(6):SpringDataRedis
数据库·redis·后端