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

相关推荐
金銀銅鐵5 小时前
类实例里还有什么——putfield、getfield 与对象传递
java·jvm·后端
织码weavecodes5 小时前
Spring Boot 接入 AI 图像生成:模型适配、图片转存与 Redis 清理
人工智能·spring boot·redis
皮皮林5516 小时前
你还在使用 WebSocket 实现实时消息推送吗?
后端
码事漫谈6 小时前
token账单到底要怎么看
后端
Cosolar7 小时前
当 Harness 标准化后,工程师还剩什么?
人工智能·后端·agent
打工仔折腾 AI7 小时前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
stark张宇8 小时前
分布式事务方案设计与选型思考:消息队列
后端
想不到一个好的ID9 小时前
什么是线程安全
后端
Dreams_l9 小时前
基于SpringBoot实现的抽奖系统(四)
java·spring boot·后端
程序员cxuan9 小时前
阿里又来一王炸,QBot 能组团干活了
人工智能·后端·程序员