我正在使用spring boot和elasticsearch进行webservice

时间:2018-01-04 19:37:17

标签: spring elasticsearch spring-data-elasticsearch

所以我试图通过TransportClient将弹簧与弹性搜索连接起来,并发生此错误。我真的尝试过很多版本的elasticsearch和spring boot,但仍然会出现这个错误:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.7.RELEASE)

2018-01-04 21:23:38.880  INFO 16168 --- [           main] com.enduser.search.Application           : Starting Application on DESKTOP-RU6VHT0 with PID 16168 (C:\Users\joo\Documents\workspace-sts-3.9.0.RELEASE\Enduser-Search-older-version\target\classes started by joo in C:\Users\joo\Documents\workspace-sts-3.9.0.RELEASE\Enduser-Search-older-version)
2018-01-04 21:23:38.896  INFO 16168 --- [           main] com.enduser.search.Application           : No active profile set, falling back to default profiles: default
2018-01-04 21:23:38.989  INFO 16168 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@43301423: startup date [Thu Jan 04 21:23:38 EET 2018]; root of context hierarchy
2018-01-04 21:23:41.338  INFO 16168 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'elasticsearchTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=elasticSearchConfiguration; factoryMethodName=elasticsearchTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/enduser/search/config/ElasticSearchConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration; factoryMethodName=elasticsearchTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]]
2018-01-04 21:23:43.366  INFO 16168 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-01-04 21:23:43.384  INFO 16168 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-01-04 21:23:43.399  INFO 16168 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.15
2018-01-04 21:23:43.602  INFO 16168 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-01-04 21:23:43.602  INFO 16168 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4644 ms
2018-01-04 21:23:43.946  INFO 16168 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-04 21:23:43.946  INFO 16168 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-04 21:23:43.946  INFO 16168 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-04 21:23:43.962  INFO 16168 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-04 21:23:43.962  INFO 16168 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-01-04 21:23:44.530  INFO 16168 --- [           main] org.elasticsearch.plugins                : [Valkyrie] modules [], plugins [], sites []
2018-01-04 21:23:47.444  INFO 16168 --- [           main] org.elasticsearch.client.transport       : [Valkyrie] failed to get node info for {#transport#-1}{127.0.0.1}{127.0.0.1:9300}, disconnecting...

org.elasticsearch.transport.NodeDisconnectedException: [][127.0.0.1:9300][cluster:monitor/nodes/liveness] disconnected

2018-01-04 21:23:47.679 ERROR 16168 --- [           main] .d.e.r.s.AbstractElasticsearchRepository : 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}]
2018-01-04 21:23:48.085  WARN 16168 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loaders': Invocation of init method failed; nested exception is NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]]
2018-01-04 21:23:48.241  INFO 16168 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-01-04 21:23:48.288  INFO 16168 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-04 21:23:48.304 ERROR 16168 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loaders': Invocation of init method failed; nested exception is NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372) [spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187) [spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176) [spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE]
    at com.enduser.search.Application.main(Application.java:11) [classes/:na]
Caused by: org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:359) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.elasticsearch.client.support.AbstractClient$IndicesAdmin.execute(AbstractClient.java:1226) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56) ~[elasticsearch-2.4.1.jar:2.4.1]
    at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.putMapping(ElasticsearchTemplate.java:207) ~[spring-data-elasticsearch-2.0.11.RELEASE.jar:na]
    at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.putMapping(ElasticsearchTemplate.java:191) ~[spring-data-elasticsearch-2.0.11.RELEASE.jar:na]
    at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.putMapping(ElasticsearchTemplate.java:186) ~[spring-data-elasticsearch-2.0.11.RELEASE.jar:na]
    at com.enduser.search.load.Loaders.loadAll(Loaders.java:30) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    ... 18 common frames omitted

此弹性搜索配置:

Settings settings;

@Bean
public Client client() throws UnknownHostException {

     Settings settings = Settings.settingsBuilder().put("cluster.name", "my-application").build();  
     TransportClient client = new TransportClient.Builder().settings(settings).build();
     client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

    return client;
}

@Bean
public ElasticsearchOperations elasticsearchTemplate() throws UnknownHostException {

    return new ElasticsearchTemplate(client());
}

}

和这个装载机类:

@Autowired
ElasticsearchOperations operations;

@Autowired
UsersRepository usersRepository;

@PostConstruct
@Transactional
public void loadAll(){

    operations.putMapping(Users.class);
    System.out.println("Loading Data");
    usersRepository.save(getData());
    System.out.printf("Loading Completed");

}

private List<Users> getData() {

    List<Users> users_list = new ArrayList<>();        

    users_list.add(new Users(1, "A", "A", "cairo", "egypt", "A@gmail.com", "software engineer", "male", 
                            "fb.com/AA", "google.com/AA", "@A", "54552222", "54552222", new GeoPoint(14.2, 12.5)));

    users_list.add(new Users(2, "B", "B", "aswan", "egypt", "B@gmail.com", "software engineer", "male", 
                             "fb.com/BB", "google.com/BB", "@B", "54552222", "54552222", new GeoPoint(14.2, 25.5)));

    users_list.add(new Users(3, "C", "C", "luxor", "egypt", "C@gmail.com", "software engineer", "male", 
                             "fb.com/CC", "google.com/CC", "@C", "54552222", "54552222", new GeoPoint(34.4, 22.5)));

    users_list.add(new Users(4, "D", "D", "cairo", "egypt", "D@gmail.com", "software engineer", "male", 
                             "fb.com/DD", "google.com/DD", "@D", "54552222", "54552222", new GeoPoint(14.2, 12.5)));

    users_list.add(new Users(5, "E", "E", "cairo", "egypt", "E@gmail.com", "software engineer", "male", 
                            "fb.com/EE", "google.com/EE", "@E", "54552222", "54552222", new GeoPoint(14.1, 12.5)));

    users_list.add(new Users(6, "F", "F", "aswan", "egypt", "F@gmail.com", "software engineer", "male", 
                             "fb.com/FF", "google.com/FF", "@F", "54552222", "54552222", new GeoPoint(14.2, 25.5)));

    users_list.add(new Users(7, "G", "G", "luxor", "egypt", "G@gmail.com", "software engineer", "male", 
                             "fb.com/GG", "google.com/GG", "@G", "54552222", "54552222", new GeoPoint(34.4, 22.5)));

    users_list.add(new Users(8, "H", "H", "cairo", "egypt", "H@gmail.com", "software engineer", "male", 
                             "fb.com/HH", "google.com/HH", "@H", "54552222", "54552222", new GeoPoint(14.7, 12.2)));

    users_list.add(new Users(9, "I", "I", "cairo", "egypt", "I@gmail.com", "software engineer", "male", 
                             "fb.com/II", "google.com/II", "@I", "54552222", "54552222", new GeoPoint(15.2, 13.5)));

    users_list.add(new Users(10, "J", "J", "aswan", "egypt", "J@gmail.com", "software engineer", "male", 
                             "fb.com/JJ", "google.com/JJ", "@J", "54552222", "54552222", new GeoPoint(11.4, 25.1)));

    users_list.add(new Users(11, "K", "K", "aswan", "egypt", "K@gmail.com", "software engineer", "male", 
                             "fb.com/KK", "google.com/KK", "@K", "54552222", "54552222", new GeoPoint(11.4, 25.1)));

    users_list.add(new Users(12, "L", "L", "aswan", "egypt", "L@gmail.com", "software engineer", "male", 
                             "fb.com/LL", "google.com/JJ", "@L", "54552222", "54552222", new GeoPoint(11.4, 25.1)));
    return users_list;
}

}

此外,当我运行我的项目并发生此错误时,弹出搜索控制台中会弹出此错误:

enter image description here

有人可以帮忙吗?

0 个答案:

没有答案