Теперь я сталкиваюсь с проблемами при попытке подключить мое приложение Spring Boot к новому серверу ELK. Я проверил, что сервер ELK работает и доступен. Однако когда я запускаю приложение Spring Boot, я получаю следующую ошибку:
Код: Выделить всё
2024-10-31T00:42:37.816+03:00 WARN 9020 --- [data-leak-service] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'Controller' defined in file [Controller.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'Service' defined in file [Service.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'DataRepository' defined in DataRepository defined in @EnableElasticsearchRepositories declared on ElasticSearchConfiguration: Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations' ...
Код: Выделить всё
@Configuration
public class ElasticSearchConfiguration {
@Value("${ElasticUrl}")
private String elkUrl;
@Value("${elasticsearch.username}")
private String username;
@Value("${elasticsearch.password}")
private String password;
@Bean
public ElasticsearchClient elasticsearchClient() {
// Set up credentials provider for basic authentication
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
AuthScope.ANY,
new UsernamePasswordCredentials(username, password)
);
// Configure RestClient with authentication
RestClient restClient = RestClient.builder(HttpHost.create(elkUrl))
.setHttpClientConfigCallback(httpClientBuilder ->
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
.build();
// Set up transport with Jackson JSON mapper
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
// Return the authenticated Elasticsearch client
return new ElasticsearchClient(transport);
}
}
Код: Выделить всё
spring.elasticsearch.index.auto-create=true
Код: Выделить всё
co.elastic.clients
elasticsearch-java
org.springframework.boot
spring-boot-starter-data-elasticsearch
I am using the Elasticsearch client version 8.15.1.
Код: Выделить всё
@Configuration
public class ElasticsearchConfig {
@Bean
public ElasticsearchClient elasticsearchClient() {
// Create the low-level client (without authentication)
RestClient restClient = RestClient.builder(HttpHost.create("http://elkip:9200")).build();
// Create the transport with a Jackson JSON mapper
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
// Create the Elasticsearch client
return new ElasticsearchClient(transport);
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... -migration