69 lines
2.0 KiB
Java
69 lines
2.0 KiB
Java
package com.njcn.influx.config;
|
|
|
|
import com.njcn.influx.base.ProxyMapperRegister;
|
|
import com.njcn.influx.core.InfluxExecutor;
|
|
import com.njcn.influx.utils.InfluxDbUtils;
|
|
import lombok.Data;
|
|
import org.influxdb.InfluxDB;
|
|
import org.influxdb.InfluxDBFactory;
|
|
import org.influxdb.impl.InfluxDBMapper;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
|
|
/**
|
|
* @author hongawen
|
|
* @version 1.0.0
|
|
*/
|
|
@Data
|
|
@Configuration
|
|
public class InfluxDbConfig {
|
|
|
|
|
|
/***
|
|
* influxMapper存放路径
|
|
*/
|
|
@Value("${spring.influx.mapper-location:com.njcn.influx.imapper}")
|
|
private String mapperLocation;
|
|
|
|
@Value("${spring.influx.database}")
|
|
private String database;
|
|
|
|
@Value("${spring.influx.url}")
|
|
private String url;
|
|
|
|
@Value("${spring.influx.user}")
|
|
private String user;
|
|
|
|
@Value("${spring.influx.password}")
|
|
private String password;
|
|
|
|
@Bean(name = "influxDbMapper")
|
|
public InfluxDBMapper influxDbMapper(InfluxDB influxDb) {
|
|
influxDb = InfluxDBFactory.connect(url, user, password,InfluxDbUtils.client);
|
|
influxDb.setLogLevel(InfluxDB.LogLevel.BASIC);
|
|
return new InfluxDBMapper(influxDb);
|
|
}
|
|
|
|
@Bean(name = "influxDbExecutor")
|
|
public InfluxExecutor executor(InfluxDB influxDb, InfluxDBMapper influxDbMapper) {
|
|
influxDb = InfluxDBFactory.connect(url, user, password,InfluxDbUtils.client);
|
|
return new InfluxExecutor(influxDb, influxDbMapper,database);
|
|
}
|
|
|
|
@Bean(name = "proxyMapperRegister")
|
|
public ProxyMapperRegister proxyMapperRegister(ConfigurableApplicationContext applicationContext, ResourceLoader resourceLoader) {
|
|
return new ProxyMapperRegister(mapperLocation, applicationContext, resourceLoader);
|
|
}
|
|
|
|
|
|
@Bean
|
|
public InfluxDbUtils influxDbUtils() {
|
|
return new InfluxDbUtils(user, password, url, database, "autogen");
|
|
}
|
|
|
|
}
|