我有一个在默认localhost主机和端口8761上运行的Eureka Server,因此我尝试通过以下方式更改此默认配置:
server:
port: 6000
servlet:
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
但是以这种方式,仅使用默认配置就无法访问eureka仪表板:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
在我的客户端中,同样的事情发生了,我无法指向不同于默认值的另一个eureka服务器(localhost:8761),请参阅我的配置:
server:
port: 7000
servlet:
context-path: /client-eureka
spring:
application:
name: client-eureka
eureka:
instance:
prefer-ip-address: true
client:
eureka-server-port: 6000
eureka-server-u-r-l-context: /myeureka
在客户端日志中查找,我得到以下信息:
2018-09-01 09:19:37.175 INFO 4931 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Replica node URL: http://localhost:8761/eureka/
无论我在客户端中配置什么端口或主机,都应始终尝试达到默认值。
重要:
我在此版本中使用eureka:https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server/2.0.1.RELEASE
最佳答案
我使用了与您相同的依赖版本,并且找不到配置路径server.servlet.contextpath
相反,您可以使用server.servlet-path或server.context-path
对于每种服务器配置,您也需要更新客户端application.yml文件。请记住,/ eureka是用于向Eureka服务器注册Eureka客户端的默认REST端点
情况1:使用server.servlet-path
尤里卡服务器:
server:
port: 7000
servlet-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
尤里卡客户:
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:7000/eureka}
instance:
preferIpAddress: true
情况2:使用server.context-path
尤里卡服务器:
server:
port: 7000
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
尤里卡客户:
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:7000/myeureka/eureka}
instance:
preferIpAddress: true
更新的答案:
由于不建议使用server.servlet-path和server.context-path,因此将eureka服务器配置如下:
server:
port: 7000
servlet:
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka客户端application.yml将与案例2相同。