[英]How to register eureka-clients with eureka-server on different hosts. Spring-boot
[英]Clients do not register with Eureka server
我的Eureka服务器(注册表)正在运行。 但是,它表明它已注册,但不可用。
我将关闭此处找到的教程,该教程说可以关闭日志记录并防止服务器自行注册。
编辑:已经确认问题不在服务器上。 现在可以注册自己了。 另外,我使用了这个演示中的客户端(在一个完全独立的项目中),该客户端向我的服务器注册了自己。
我的客户端现在无法运行。 这是pom文件的依赖项:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.nt.springframework.data</groupId>
<artifactId>nt-spring-data-marklogic</artifactId>
<version>1.1.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<version>2.0.0.RC3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-stream-binder-kafka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.11</version>
</dependency>
这是客户端主文件:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.marklogic.repository.config.EnableMarkLogicRepositories;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
@EnableMarkLogicRepositories("com.example.repository")
@ComponentScan({"com.id.example"})
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class ClientApp {
public static void main(String[] args) {
System.out.println("Starting app...");
SpringApplication.run(ClientApp.class, args);
}
}
这是错误:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.10.RELEASE)
[2018-04-23 16:27:44.811] - 91242 INFO [main] --- org.apache.catalina.core.StandardService: Starting service [Tomcat]
[2018-04-23 16:27:44.816] - 91242 INFO [main] --- org.apache.catalina.core.StandardEngine: Starting Servlet Engine: Apache Tomcat/8.5.27
[2018-04-23 16:27:45.163] - 91242 INFO [localhost-startStop-1] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]: Initializing Spring embedded WebApplicationContext
[2018-04-23 16:28:04.271] - 91242 INFO [main] --- org.apache.catalina.core.StandardService: Stopping service [Tomcat]
Exception in thread "main" org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.ibm.tsd.TradeServiceDemoApplication.main(TradeServiceDemoApplication.java:21)
Caused by: java.lang.NullPointerException
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:80)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
... 14 more
任何帮助,将不胜感激!
您必须将“服务器应用程序”(称为EurekaServerApplication
)与“客户端应用程序”(称为EurekaClientApplication)分开:
在服务器应用程序中,添加eureka-server
依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
您的服务器应用程序必须使用@EnableEurekaServer
批注装饰
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {..}
将'eureka-client'依赖项添加到Client-application的pom.xml
中:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
在客户端application.properties
或application.yml
您必须具有:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
当然,端口值8761必须与服务器应用程序中的端口值相同:
server:
port: ${PORT:8761}
注意:您无需使用@EnableEurekaClient
或@EnableDiscoveryClient
注释来装饰ClientEurekaApplication,即可从@EnableEurekaClient
或从@EnableDiscoveryClient
发现您的客户端。
我正在为这样的客户端( yml
)使用配置:
server:
port: 8080
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: clientname
您可以继续使用application.properties
而不是yml
。 只需添加spring.application.name=applicationname
请检查您是否忘记设置applicationname
。 另外,在启动client
之前,请确保您的discovery-service
已启动。
要查看您的eureka-service
您需要转到http://localhost:8761
。 要访问您的client
使用http://localhost:8761/clientname
我在一个必须升级的项目中遇到此错误,并且修复了该错误,从而消除或删除了Maven中的某些库依赖项。 在为杰克逊5或泽西岛相关内容选择正确的库时,这会导致问题。
查看您的依赖性层次结构,然后开始播放或排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.