Eureka Server 中的服务注册问题
Service Registry Issue in Eureka Server
我在使用 Spring Eureka Server 启动注册表时遇到问题。发现服务已注册,另一个未注册。
我的application.yml发现如下,
spring:
application:
name: swimming-pool-discovery-client
server:
port: 8761
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
注册服务application.yml如下。
spring:
application:
name: swimming-pool-reservation-service
server:
port: 8181
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
发现pom.xml如下,
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<artifactId>discovery-service</artifactId>
<properties>
<java-version>1.8</java-version>
<docker.image.prefix>swimming-pool</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
我的注册pom.xml如下,
<properties>
<java-version>1.8</java-version>
<docker.image.prefix>swimming-pool</docker.image.prefix>
</properties>
<artifactId>reservation-service</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
Java 类 是,
@EnableEurekaServer
@SpringBootApplication
public class DisoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DisoveryApplication.class, args);
}
}
@SpringBootApplication
@EnableDiscoveryClient
@EnableEurekaClient
public class ReservationApplication {
public static void main(String[] args) {
SpringApplication.run(ReservationApplication.class, args);
}
}
我面临以下异常,
reservation-service_1 | 2018-04-17 14:26:36.428 WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
reservation-service_1 | 2018-04-17 14:26:36.429 WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SWIMMING-POOL-RESERVATION-SERVICE/d34463b43007:swimming-pool-reservation-service:8181 - registration failed Cannot execute request on any known server
reservation-service_1 |
reservation-service_1 | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:798) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104) [eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
reservation-service_1 | at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
reservation-service_1 |
reservation-service_1 | 2018-04-17 14:26:36.430 WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
任何帮助将不胜感激?
您的发现服务配置不正确。把你的 application.yml
改成这样
spring:
application:
name: swimming-pool-discovery-client
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
您的注册服务配置正确。但是你不需要 @EnableDiscoveryClient
和
@EnableEurekaClient
两个都。只需使用 @EnableEurekaClient
我在使用 Spring Eureka Server 启动注册表时遇到问题。发现服务已注册,另一个未注册。
我的application.yml发现如下,
spring:
application:
name: swimming-pool-discovery-client
server:
port: 8761
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
注册服务application.yml如下。
spring:
application:
name: swimming-pool-reservation-service
server:
port: 8181
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
发现pom.xml如下,
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<artifactId>discovery-service</artifactId>
<properties>
<java-version>1.8</java-version>
<docker.image.prefix>swimming-pool</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
我的注册pom.xml如下,
<properties>
<java-version>1.8</java-version>
<docker.image.prefix>swimming-pool</docker.image.prefix>
</properties>
<artifactId>reservation-service</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
Java 类 是,
@EnableEurekaServer
@SpringBootApplication
public class DisoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DisoveryApplication.class, args);
}
}
@SpringBootApplication
@EnableDiscoveryClient
@EnableEurekaClient
public class ReservationApplication {
public static void main(String[] args) {
SpringApplication.run(ReservationApplication.class, args);
}
}
我面临以下异常,
reservation-service_1 | 2018-04-17 14:26:36.428 WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
reservation-service_1 | 2018-04-17 14:26:36.429 WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SWIMMING-POOL-RESERVATION-SERVICE/d34463b43007:swimming-pool-reservation-service:8181 - registration failed Cannot execute request on any known server
reservation-service_1 |
reservation-service_1 | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:798) ~[eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104) [eureka-client-1.6.2.jar!/:1.6.2]
reservation-service_1 | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
reservation-service_1 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
reservation-service_1 | at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
reservation-service_1 |
reservation-service_1 | 2018-04-17 14:26:36.430 WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
任何帮助将不胜感激?
您的发现服务配置不正确。把你的 application.yml
改成这样
spring:
application:
name: swimming-pool-discovery-client
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
您的注册服务配置正确。但是你不需要 @EnableDiscoveryClient
和
@EnableEurekaClient
两个都。只需使用 @EnableEurekaClient