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会进行自动关闭
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)