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会进行自动关闭

相关推荐
盒马盒马8 分钟前
Rust:内部可变性 & 型变
开发语言·后端·rust
无限大622 分钟前
为什么玩游戏需要独立显卡?——GPU与CPU的分工协作
后端·程序员
可涵不会debug31 分钟前
时序数据库选型指南:Apache IoTDB,大数据时代的时序数据管理利器
apache·时序数据库·iotdb
Moment34 分钟前
小米不仅造车,还造模型?309B参数全开源,深度思考完胜DeepSeek 🐒🐒🐒
前端·人工智能·后端
马卡巴卡1 小时前
SpringBoot集成Spring Statemachine(状态机)实战教程
后端
酒酿萝卜皮1 小时前
Elastic Search 安装使用
后端
kkk_皮蛋1 小时前
信令是什么?为什么 WebRTC 需要信令?
后端·asp.net·webrtc
库库林_沙琪马1 小时前
5、Seata
分布式·后端
王桑.2 小时前
Spring中IoC的底层原理
java·后端·spring