I have an application built using the Jhipter generator based on Spring Boot. The latest version of Jhipster allows you to enable Elasticsearch as an option, so I have an application that launches an embedded instance of Elasticsearch in development mode and connects to the server instance in production mode.
When the application runs in development mode, it connects perfectly to the embedded instance, but if I try to connect to an external instance, I get the following error on the console:
ERROR 7804 --- [restartedMain] .dersAbstractElasticsearchRepository: failed to load elasticsearch nodes: org.elasticsearch.client.transport.NoNodeAvailableException: none of the configured nodes are available: [{# transport # -1} {127.0.0.1} {127.0 .0.1: 9300}]
My application uses Spring version to download 1.4.0.RELEASE , and according to elasticsearch.yml the application has elasticsearch 2.3.5
Settings of my application-prod.yml:
spring: data: elasticsearch: cluster-name: cluster-nodes: localhost:9300
By default, ElasticSearchConfiguration:
@Configuration public class ElasticSearchConfiguration { @Bean public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) { return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())); } }
What I override with:
@Configuration public class ElasticSearchConfiguration { @Value("${spring.data.elasticsearch.cluster-name}") private String clusterName; @Value("${spring.data.elasticsearch.cluster-nodes}") private String clusterNodes; @Bean public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException { String server = clusterNodes.split(":")[0]; Integer port = Integer.parseInt(clusterNodes.split(":")[1]); Settings settings = Settings.settingsBuilder() .put("cluster.name", clusterName).build(); client = TransportClient.builder().settings(settings).build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(server), port)); return new ElasticsearchTemplate(client); } }
But I still cannot connect elasticsearch using prod yml.
During debugging, I received the following error, while the ElasticearchTemplate bean creation:
The method threw an exception "java.lang.StackOverflowError". Unable to evaluate org.elasticsearch.common.inject.InjectorImpl.toString ()
How can I solve this problem?
java spring-boot elasticsearch jhipster
ajain
source share