为了账号安全,请及时绑定邮箱和手机立即绑定

Maven群项目启动报错,多个服务依赖关系

2018-05-04 18:30:03.369  INFO 8616 --- [           main] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2018-05-04 18:30:03.419  INFO 8616 --- [           main] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2018-05-04 18:30:03.419  INFO 8616 --- [           main] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2018-05-04 18:30:03.419  INFO 8616 --- [           main] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2018-05-04 18:30:03.420  INFO 8616 --- [           main] com.netflix.discovery.DiscoveryClient    : Application is null : false
2018-05-04 18:30:03.420  INFO 8616 --- [           main] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2018-05-04 18:30:03.420  INFO 8616 --- [           main] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2018-05-04 18:30:03.420  INFO 8616 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2018-05-04 18:30:04.512 ERROR 8616 --- [           main] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
    at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
    at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.6.2.jar:1.6.2]
    at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509) ~[jersey-client-1.19.1.jar:1.19.1]
    at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplicationsInternal(AbstractJerseyEurekaHttpClient.java:194) ~[eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplications(AbstractJerseyEurekaHttpClient.java:165) ~[eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73) ~[eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118) ~[eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79) ~[eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:119) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) [eureka-client-1.6.2.jar:1.6.2]
    at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1013) [eureka-client-1.6.2.jar:1.6.2]


正在回答

3 回答

看看是不是所需要的类用错了;

0 回复 有任何疑惑可以回复我~
#1

小小阿克 提问者

嗯,注入的类好像没进来
2018-08-09 回复 有任何疑惑可以回复我~
package com.stono.sboot01;

import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

@SpringBootApplication
@RestController
public class Sboot01Application {

   @Autowired
   private TransportClient client;

   @GetMapping("/get/book/novel")
   @ResponseBody
   public ResponseEntity get(@RequestParam(name = "id", defaultValue = "") String id) {
       if (id.isEmpty()) {
           return new ResponseEntity(HttpStatus.NOT_FOUND);
       }
       GetResponse result = this.client.prepareGet("book", "novel", id).get();
       if (!result.isExists()) {
           return new ResponseEntity(HttpStatus.NOT_FOUND);
       }
       return new ResponseEntity(result.getSource(), HttpStatus.OK);
   }

   @PostMapping("add/book/novel")
   @ResponseBody
   public ResponseEntity add(
           @RequestParam(name = "title") String title,
           @RequestParam(name = "author") String author,
           @RequestParam(name = "word_count") int wordCount,
           @RequestParam(name = "publish_date")
                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishDate
           ) {
       try {
           XContentBuilder content = XContentFactory.jsonBuilder()
                   .startObject()
                   .field("title", title)
                   .field("author", author)
                   .field("word_count", wordCount)
                   .field("publish_date", publishDate.getTime())
                   .endObject();
           IndexResponse response = this.client.prepareIndex("book", "novel")
                   .setSource(content)
                   .get();
           return new ResponseEntity(response.getId(), HttpStatus.OK);
       } catch (IOException e) {
           e.printStackTrace();
           return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
       }

   }
   @GetMapping("/")
   public String index() {
       return "index";
   }

   @DeleteMapping("delete/book/novel")
   @ResponseBody
   public ResponseEntity delete(@RequestParam(name = "id") String id) {
       DeleteResponse deleteResponse = this.client.prepareDelete("book", "novel", id).get();
       return new ResponseEntity(deleteResponse.toString(), HttpStatus.OK);
   }

   @PutMapping("update/book/novel")
   @ResponseBody
   public ResponseEntity update(
           @RequestParam(name = "id") String id,
           @RequestParam(name = "title", required = false) String title,
           @RequestParam(name = "author", required = false) String author,
           @RequestParam(name = "word_count",required = false) int wordCount,
           @RequestParam(name = "publish_date",required = false) Date publishDate
   ) {
       UpdateRequest updateRequest = new UpdateRequest("book","novel",id);
       try {
           XContentBuilder builder = XContentFactory.jsonBuilder()
                   .startObject();
           if(title != null){
               builder.field("title", title);
           }
           if (author != null) {
               builder.field("author", author);
           }
           builder.endObject();
           updateRequest.doc(builder);
       } catch (IOException e) {
           e.printStackTrace();
           return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
       }
       try {
           UpdateResponse response = this.client.update(updateRequest).get();
           return new ResponseEntity(response.getResult().toString(), HttpStatus.OK);
       } catch ( Exception e) {
           e.printStackTrace();
           return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
       }

   }

   @PostMapping("query/book/novel")
   @ResponseBody
   public ResponseEntity query(
           @RequestParam(name = "author",required = false) String author,
           @RequestParam(name = "title",required = false) String title,
           @RequestParam(name = "gt_word_count", defaultValue = "0") int gtWordCount,
           @RequestParam(name = "lt_word_count", required = false) Integer ltWordCount
   ) {
       BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
       if (author != null) {
           boolQueryBuilder.must(QueryBuilders.matchQuery("author", author));
       }
       if (title != null) {
           boolQueryBuilder.must(QueryBuilders.matchQuery("title", title));
       }
       RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("word_count").from(gtWordCount);
       if (ltWordCount != null && ltWordCount>0) {
           rangeQueryBuilder.to(ltWordCount);
       }
       boolQueryBuilder.filter(rangeQueryBuilder);
       SearchRequestBuilder searchRequestBuilder = this.client.prepareSearch("book")
               .setTypes("novel")
               .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
               .setQuery(boolQueryBuilder)
               .setFrom(0)
               .setSize(10);
       System.out.println(searchRequestBuilder);
       SearchResponse searchResponse = searchRequestBuilder.get();
       List<Map<String, Object>> result = new ArrayList<>();
       for (SearchHit hit : searchResponse.getHits()) {
           result.add(hit.getSource());
       }
       return new ResponseEntity(result, HttpStatus.OK);

   }
   public static void main(String[] args) {
       SpringApplication.run(Sboot01Application.class, args);
   }
}


0 回复 有任何疑惑可以回复我~

这个是连接没有创建上啊;好像不是依赖的问题;

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Maven群项目启动报错,多个服务依赖关系

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信