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

相关推荐
用户7344028193424 分钟前
Docker配置daemon.json
后端
架构师沉默12 分钟前
女孩去旅行,给男朋友带回了一个难解的 Bug
java·后端·架构
月光宝鉴14 分钟前
如何将excel中文件转为json
后端
刘 大 望22 分钟前
SpringAI Tool Calling(工具调用)
java·spring boot·spring·ai·maven·intellij-idea·文心一言
stark张宇40 分钟前
告别混乱接口:RESTful API 规范实战指南
后端
uzong1 小时前
Dubbo 版本升级 3.0.10 升级到 3.1.11 ,3.0.10升级到3.2.16 (过程素材、仅供参考)
后端
dovens1 小时前
Spring Boot(快速上手)
java·spring boot·后端
元Y亨H1 小时前
深入理解基于角色的访问控制(RBAC)
后端
木易士心2 小时前
从 MVP 到千万级并发:AI 在前后端开发中的差异化落地指南
前端·后端