首先为了方便本地测试,可以选择下载window版的influxdb,我在官网下载的是influxdb2-2.0.9-windows-amd64.zip。
然后在解压,在该文件夹下cmd进入命令窗口,用命令 influxd.exe回车就启动了。
访问http://localhost:8086/就能看到界面了。
influxdb2.0和1.x的区别很大,pom中引入:
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>3.0.1</version>
</dependency>
yml的配置:
spring:
influx:
url: http://localhost:8086
token: vGLGb5rK5f3-l_uR9JEfLM1iNgOJfMPjkGXA9xANd2SbmXeKbneV1vshdT_nsxtleHokXzP-M6f0ESXZyJJSNg== #可以从页面上获取
org:
bucket: mydb
配置类
/**
* influx配置类
*/
@Configuration
public class InfluxDbConfig {
@Value("${spring.influx.token:''}")
private String token;
@Value("${spring.influx.url:''}")
private String url;
@Bean
public InfluxDBClient influxDBClient() {
System.out.println("=============="+token+"=============="