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

相关推荐
一点程序7 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
奋进的芋圆9 小时前
Spring Boot 实现三模安全登录:微信扫码 + 手机号验证码 + 邮箱验证码
spring boot·redis·微信
怪兽源码9 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
csdn_aspnet9 小时前
ASP.NET Core 中的依赖注入
后端·asp.net·di·.net core
昊坤说不出的梦10 小时前
【实战】监控上下文切换及其优化方案
java·后端
疯狂踩坑人10 小时前
【Python版 2026 从零学Langchain 1.x】(二)结构化输出和工具调用
后端·python·langchain
m0_7400437312 小时前
【无标题】
java·spring boot·spring·spring cloud·微服务
重整旗鼓~12 小时前
1.外卖项目介绍
spring boot
橘子师兄12 小时前
C++AI大模型接入SDK—ChatSDK封装
开发语言·c++·人工智能·后端
@ chen12 小时前
Spring事务 核心知识
java·后端·spring