web-dev-qa-db-ja.com

Spring Cloudを使用してEurekaサーバーのデフォルトポートを変更する

私は、スプリングブートアプリケーション、eurekaサーバー、およびeurekaクライアントを取得しました。

これが私のサーバー設定です

server:
  port: 8761

spring:
  application:
    name: eureka-server

これが私のサーバーコードです

package fr.maif.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableEurekaServer
@EnableZuulProxy
public class EurekaServerApplication {

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

これがクライアント構成です

spring:
  application:
    name: eureka-client
server:
  port: 8083
eureka:
  client:
    serviceUrl:
      defaultZone: "http://localhost:8761/eureka"

これが私のクライアントコードです

package fr.maif.eurekaclient;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientApplication {

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

上記は完全に機能し、サーバーポートは8761のままですが、サーバーポートとクライアントのdefaultZone構成の両方で(8080またはその他の値に)変更しようとすると、サーバーは継続的にConnectExceptionsをスローします。

2017-08-10 15:54:31.424 ERROR 22219 --- [get_localhost-4] c.n.e.cluster.ReplicationTaskProcessor   : Network level connection to peer localhost; retrying after delay

com.Sun.jersey.api.client.ClientHandlerException: Java.net.ConnectException: Connection refused (Connection refused)
    at com.Sun.jersey.client.Apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.Java:187) ~[jersey-Apache-client4-1.19.1.jar:1.19.1]
    at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.Java:48) ~[eureka-core-1.6.2.jar:1.6.2]
    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.post(WebResource.Java:570) ~[jersey-client-1.19.1.jar:1.19.1]
    at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.Java:116) ~[eureka-core-1.6.2.jar:1.6.2]
    at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.Java:71) ~[eureka-core-1.6.2.jar:1.6.2]
    at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.Java:187) [eureka-core-1.6.2.jar:1.6.2]
    at Java.lang.Thread.run(Thread.Java:748) [na:1.8.0_131]
Caused by: Java.net.ConnectException: Connection refused (Connection refused)
    at Java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_131]
    at Java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.Java:350) ~[na:1.8.0_131]
    at Java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.Java:206) ~[na:1.8.0_131]
    at Java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.Java:188) ~[na:1.8.0_131]
    at Java.net.SocksSocketImpl.connect(SocksSocketImpl.Java:392) ~[na:1.8.0_131]
    at Java.net.Socket.connect(Socket.Java:589) ~[na:1.8.0_131]
    at org.Apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.Java:121) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.Java:180) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.Java:144) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.Java:134) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.Java:610) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.Java:445) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.Java:835) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.Java:118) ~[httpclient-4.5.3.jar:4.5.3]
    at org.Apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.Java:56) ~[httpclient-4.5.3.jar:4.5.3]
    at com.Sun.jersey.client.Apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.Java:173) ~[jersey-Apache-client4-1.19.1.jar:1.19.1]
    ... 10 common frames omitted

何が悪いのでしょうか?

6

次の構成を試してください。1.サーバー。

server:
  port: 8080

eureka:
  instance:
   hostname: localhost
client:
  registerWithEureka: false
  fetchRegistry: false
  serviceUrl:
  defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

2.クライアント。

spring:
  application:
  name: eureka-client
server:
  port: 8083
eureka:
  client:
  registerWithEureka: true
  fetchRegistry: true
  serviceUrl:
    defaultZone: http://localhost:8080/eureka/
12
Shchipunov