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