spring - Elasticsearch doesn't work after create repository No qualifying bean of type 'java.lang.Class<org.springframework.data.repository.Repository<?, ?>>' -
hello have problem spring data elasticsearch can connect elasticsearch after create repository program stop working code. thank in advance solve problem
@configuration @enableelasticsearchrepositories(basepackages = "com.storyworld.repository.elastic") public class elasticsearchconfig { private static final string property_elastic_host = "localhost"; private static final int property_elastic_port = 9300; private static final string property_elastic_cluster_name = "elasticsearch"; @bean public elasticsearchoperations elasticsearchtemplate() throws exception { return new elasticsearchtemplate(client()); } @bean public client client() throws exception { settings essettings = settings.settingsbuilder().put("cluster.name", property_elastic_cluster_name).build(); return transportclient.builder().settings(essettings).build().addtransportaddress( new inetsockettransportaddress(inetaddress.getbyname(property_elastic_host), property_elastic_port)); } }
this repository:
public interface chatrepository extends elasticsearchrepository<chat, string>{}
and class chat:
@document(indexname = "chatest", type = "chat") public class chat { @id private string id; private string message; }
after create repository got error:
479 [localhost-startstop-1] error org.springframework.web.context.contextloader [] - context initialization failed org.springframework.beans.factory.unsatisfieddependencyexception: error creating bean name 'chatrepository': unsatisfied dependency expressed through constructor parameter 0; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type 'java.lang.class<org.springframework.data.repository.repository<?, ?>>' available: expected @ least 1 bean qualifies autowire candidate. dependency annotations: {} @ org.springframework.beans.factory.support.constructorresolver.createargumentarray(constructorresolver.java:749) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.constructorresolver.autowireconstructor(constructorresolver.java:189) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.autowireconstructor(abstractautowirecapablebeanfactory.java:1154) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1056) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:513) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:483) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:740) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:866) ~[spring-context-4.3.5.release.jar:4.3.5.release] @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:542) ~[spring-context-4.3.5.release.jar:4.3.5.release] @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:444) ~[spring-web-4.3.5.release.jar:4.3.5.release] @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:326) [spring-web-4.3.5.release.jar:4.3.5.release] @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:107) [spring-web-4.3.5.release.jar:4.3.5.release] @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4725) [catalina.jar:?] @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5189) [catalina.jar:?] @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) [catalina.jar:?] @ org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:724) [catalina.jar:?] @ org.apache.catalina.core.containerbase.addchild(containerbase.java:700) [catalina.jar:?] @ org.apache.catalina.core.standardhost.addchild(standardhost.java:734) [catalina.jar:?] @ org.apache.catalina.startup.hostconfig.deploydescriptor(hostconfig.java:596) [catalina.jar:8.5.6-dev] @ org.apache.catalina.startup.hostconfig$deploydescriptor.run(hostconfig.java:1805) [catalina.jar:8.5.6-dev] @ java.util.concurrent.executors$runnableadapter.call(unknown source) [?:1.8.0_121] @ java.util.concurrent.futuretask.run(unknown source) [?:1.8.0_121] @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) [?:1.8.0_121] @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) [?:1.8.0_121] @ java.lang.thread.run(unknown source) [?:1.8.0_121] caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type 'java.lang.class<org.springframework.data.repository.repository<?, ?>>' available: expected @ least 1 bean qualifies autowire candidate. dependency annotations: {} @ org.springframework.beans.factory.support.defaultlistablebeanfactory.raisenomatchingbeanfound(defaultlistablebeanfactory.java:1474) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:1102) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:1064) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.constructorresolver.resolveautowiredargument(constructorresolver.java:835) ~[spring-beans-4.3.5.release.jar:4.3.5.release] @ org.springframework.beans.factory.support.constructorresolver.createargumentarray(constructorresolver.java:741) ~[spring-beans-4.3.5.release.jar:4.3.5.release] ... 28 more
i think issue occurs because jparepository config jpa
@configuration @enablejparepositories(basepackages = "com.storyworld.repository.sql") public class mysqlconfig { private static final string property_name_database_driver = "com.mysql.jdbc.driver"; private static final string property_name_database_password = "root"; private static final string property_name_database_url = "jdbc:mysql://localhost:3306/storyworld?usessl=false"; private static final string property_name_database_username = "root"; private static final string property_name_hibernate_dialect = "org.hibernate.dialect.mysql5dialect"; private static final string property_name_hibernate_show_sql = "true"; private static final string property_name_entitymanager_packages_to_scan = "com.storyworld.domain.sql"; private static final string property_name_hibernate_auto = "update"; @bean public datasource datasource() { drivermanagerdatasource datasource = new drivermanagerdatasource(); datasource.setdriverclassname(property_name_database_driver); datasource.seturl(property_name_database_url); datasource.setusername(property_name_database_username); datasource.setpassword(property_name_database_password); return datasource; } private properties gethibernateproperties() { properties properties = new properties(); properties.put("hibernate.show_sql", property_name_hibernate_show_sql); properties.put("hibernate.dialect", property_name_hibernate_dialect); properties.put("hibernate.hbm2ddl.auto", property_name_hibernate_auto); return properties; } @bean public entitymanagerfactory entitymanagerfactory() { hibernatejpavendoradapter vendoradapter = new hibernatejpavendoradapter(); vendoradapter.setgenerateddl(true); localcontainerentitymanagerfactorybean factory = new localcontainerentitymanagerfactorybean(); factory.setjpavendoradapter(vendoradapter); factory.setpackagestoscan(property_name_entitymanager_packages_to_scan); factory.setdatasource(datasource()); factory.setjpaproperties(gethibernateproperties()); factory.afterpropertiesset(); return factory.getobject(); } @bean public platformtransactionmanager transactionmanager() { jpatransactionmanager txmanager = new jpatransactionmanager(); txmanager.setentitymanagerfactory(entitymanagerfactory()); return txmanager; } }
i think , might because of dependencies conflict , because common dependency shared spring data elastic search , spring data jpa .
i using code , try . sure solve issue :-
<!-- spring elasticsearch data jpa--> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-elasticsearch</artifactid> <version>2.0.1.release</version> </dependency> <!-- spring data jpa--> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-jpa</artifactid> <version>1.10.1.release</version> </dependency>
Comments
Post a Comment