Failed to run project after adding elasticsearch

I want to run my project with this properties (using elasticsearch). But fails with this tomcat log.
Note :

                setProperty("hibernate.search.default.indexmanager", "elasticsearch");
                setProperty("hibernate.search.default.elasticsearch.host", "http://localhost:9200");
                setProperty("hibernate.search.default.elasticsearch.index_schema_management_strategy", "drop-and-create-and-drop");
                setProperty("hibernate.search.default.elasticsearch.index_management_wait_timeout","10000");
                setProperty("hibernate.search.default.elasticsearch.required_index_status", "green");
                setProperty("hibernate.search.default.elasticsearch.refresh_after_write", "true");
            }

Note: With Bellow Config. Its Ok.

                setProperty("hibernate.search.default.directory_provider", "filesystem");
                setProperty("hibernate.search.default.indexBase", "/dir");
                setProperty("hibernate.search.Rules.directory_provider", "filesystem");
                setProperty("hibernate.search.jmx_enabled", "true");
                setProperty("hibernate.search.generate_statistics", "true");

Dependencies:

lucene-core : 5.5.5
hibernate-search-orm : 5.8.2
hibernate-search-elasticsearch : 5.8.2
hibernate-core : 5.2.8.Final

Output:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'mainEntityManagerFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/http/conn/util/PublicSuffixMatcherLoader
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 218 more
Caused by: java.lang.NoClassDefFoundError: org/apache/http/conn/util/PublicSuffixMatcherLoader
	at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:640)
	at org.elasticsearch.client.RestClientBuilder$1.run(RestClientBuilder.java:213)
	at org.elasticsearch.client.RestClientBuilder$1.run(RestClientBuilder.java:210)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.elasticsearch.client.RestClientBuilder.createHttpClient(RestClientBuilder.java:210)
	at org.elasticsearch.client.RestClientBuilder.build(RestClientBuilder.java:184)
	at org.hibernate.search.elasticsearch.client.impl.DefaultElasticsearchClientFactory.createClient(DefaultElasticsearchClientFactory.java:100)
	at org.hibernate.search.elasticsearch.client.impl.DefaultElasticsearchClientFactory.create(DefaultElasticsearchClientFactory.java:65)
	at org.hibernate.search.elasticsearch.impl.DefaultElasticsearchService.start(DefaultElasticsearchService.java:95)
	at org.hibernate.search.engine.service.impl.StandardServiceManager$ServiceWrapper.startService(StandardServiceManager.java:325)
	at org.hibernate.search.engine.service.impl.StandardServiceManager$ServiceWrapper.startVirtual(StandardServiceManager.java:290)
	at org.hibernate.search.engine.service.impl.StandardServiceManager.createAndCacheWrapper(StandardServiceManager.java:227)
	at org.hibernate.search.engine.service.impl.StandardServiceManager.requestService(StandardServiceManager.java:100)
	at org.hibernate.search.elasticsearch.impl.ElasticsearchIndexManager.initialize(ElasticsearchIndexManager.java:153)
	at org.hibernate.search.indexes.impl.IndexManagerGroupHolder.doCreateIndexManager(IndexManagerGroupHolder.java:195)
	at org.hibernate.search.indexes.impl.IndexManagerGroupHolder.getOrCreateIndexManager(IndexManagerGroupHolder.java:155)
	at org.hibernate.search.indexes.impl.NotShardedEntityIndexBinder.bind(NotShardedEntityIndexBinder.java:34)
	at org.hibernate.search.indexes.impl.IndexManagerGroupHolder.bind(IndexManagerGroupHolder.java:100)
	at org.hibernate.search.indexes.impl.IndexManagerHolder.buildEntityIndexBinding(IndexManagerHolder.java:100)
	at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:428)
	at org.hibernate.search.spi.SearchIntegratorBuilder.createNewFactoryState(SearchIntegratorBuilder.java:244)
	at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:200)
	at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:128)
	at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.boot(HibernateSearchSessionFactoryObserver.java:127)
	at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:94)
	at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:371)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
	at ir.mbazar.common.config.configuration.MainPersistenceConfig.mainEntityManagerFactoryBean(MainPersistenceConfig.java:81)
	at ir.mbazar.common.config.configuration.MainPersistenceConfig$$EnhancerBySpringCGLIB$$2cee3b61.CGLIB$mainEntityManagerFactoryBean$1(<generated>)
	at ir.mbazar.common.config.configuration.MainPersistenceConfig$$EnhancerBySpringCGLIB$$2cee3b61$$FastClassBySpringCGLIB$$7808f57.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
	at ir.mbazar.common.config.configuration.MainPersistenceConfig$$EnhancerBySpringCGLIB$$2cee3b61.mainEntityManagerFactoryBean(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 219 more
Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.util.PublicSuffixMatcherLoader
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1309)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1138)
	... 263 more


After add bellow dependency. Problem Solved.

      <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
            <version>4.1.4</version>
      </dependency>

This is usually not necessary because hibernate-search-elasticsearch declares a dependency to elasticsearch-rest-client, which transitively depends on httpasyncclient:

[INFO] org.hibernate:hibernate-search-elasticsearch:jar:5.8.2.Final
[INFO] +- org.hibernate:hibernate-search-engine:jar:5.8.2.Final:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  +- org.apache.lucene:lucene-core:jar:5.5.5:compile
[INFO] |  +- org.apache.lucene:lucene-misc:jar:5.5.5:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-common:jar:5.5.5:compile
[INFO] |  +- org.apache.lucene:lucene-facet:jar:5.5.5:compile
[INFO] |  |  \- org.apache.lucene:lucene-queries:jar:5.5.5:compile
[INFO] |  +- org.apache.lucene:lucene-queryparser:jar:5.5.5:compile
[INFO] |  \- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] +- org.jboss.logging:jboss-logging-annotations:jar:2.0.1.Final:provided
[INFO] +- org.elasticsearch.client:elasticsearch-rest-client:jar:5.6.2:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.5:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.elasticsearch.client:elasticsearch-rest-client-sniffer:jar:5.6.2:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.6:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.2:compile

There is probably another problem in your POM.
Anyway, glad you solved it.

1 Like