我正在尝试在应该连接到 influxDB 的 RestController 中的 Spring Boot 项目上运行 findAll 类型方法。 该方法应该从流入表中获取所有数据并将其保存在 postgres 表中。 这是我的 InfluxDB 配置类:
@Configuration
public class InfluxDBConfig {
@Value("${spring.influx.url}")
private String influxDBUrl;
@Value("${spring.influx.user}")
private String userName;
@Value("${spring.influx.password}")
private String password;
@Value("${spring.influx.database}")
private String database;
@Bean
public InfluxDB influxDB() throws Exception {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
OkHttpClient.Builder okhttpClientBuilder = new OkHttpClient.Builder();
okhttpClientBuilder.sslSocketFactory(sf.sslContext.getSocketFactory(), (X509TrustManager) trustManagers[0]);
InfluxDB influxDB = InfluxDBFactory.connect(influxDBUrl, userName, password, okhttpClientBuilder);
try {
influxDB.setDatabase(database).enableBatch(100, 2000, TimeUnit.MILLISECONDS);
} catch (Exception e) {
e.printStackTrace();
} finally {
influxDB.setRetentionPolicy("autogen");
}
influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
return influxDB;
}
}
这是我在 RestController 类中实现的 getAll 方法:
@ApiOperation(value = "Finds all values of Monterotondo Marittimo without query in input", authorizations = {
@Authorization(value = OAUTH_SCHEMA_NAME) })
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden") })
@GetMapping("/Monterotondo-Marittimo/all")
public List<MonterotondoMarittimoModel> getAll() {
final String METHOD_NAME = "getAll(token)";
try {
startLog(METHOD_NAME);
final List<MonterotondoMarittimoEntity> result = monterotondoMarittimoService.getAll();
final List<MonterotondoMarittimoModel> response = ModelMapUtils.createObject(result,
MonterotondoMarittimoModel.class);
endLog(METHOD_NAME, response);
return response;
} catch (final Exception e) {
errorLog(METHOD_NAME, e);
throw e;
}
}
这是在我的服务类中实现的方法 getAll:
@Transactional
public List<MonterotondoMarittimoEntity> getAll() {
final String METHOD_NAME = "getAll()";
startLog(METHOD_NAME);
List<MonterotondoMarittimoEntity> result = new ArrayList<MonterotondoMarittimoEntity>();
Instant start = Instant.now();
final Query query = new Query("SELECT * FROM Monterotondo_Marittimo LIMIT 5");
QueryResult queryResult = influxDB.query(query);
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
Instant finish = Instant.now();
long timeElapsed = Duration.between(start, finish).toMillis();
result = resultMapper.toPOJO(queryResult, MonterotondoMarittimoEntity.class);
if (!result.isEmpty()) {
for (MonterotondoMarittimoEntity monterotondoMarittimoEntity : result) {
MonterotondoMarittimoEntityPstgrs monterotondoMarittimoEntityPstgrs = new MonterotondoMarittimoEntityPstgrs();
monterotondoMarittimoEntityPstgrs = ConvertersUtils
.createMonterotondoMarittimoEntityPstgrsFromMonterotondoMarittimoEntity(
monterotondoMarittimoEntity);
monterotondoMarittimoDao.save(monterotondoMarittimoEntityPstgrs);
logger.info("Table Updated");
}
}
endLog(METHOD_NAME, result);
return result;
}
这是我的应用程序属性:
### Application server ###
server.port=30223
### DATABASE POSTGRES LOCAL ###
#spring.jpa.hibernate.ddl-auto=update
#spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
#spring.datasource.username=postgres
#spring.datasource.password=postgres
### INFLUX ###
spring.influx.url=https://xxxxx:30577
spring.influx.user=guixxx
spring.influx.password=abcxxxx123
spring.influx.database=xxx_db
访问 influx db 的凭据是正确的 但是当我尝试从我的招摇中启动 chimaata 时,我收到以下错误:
org.influxdb.InfluxDBException: Invalid credentials
我该怎么做才能解决问题? 也许我应该使用一个令牌,将输入传递给方法,我通常用它来查询邮递员。但我不知道该怎么做。 请帮帮我