我有一个Eureka Server在默认的localhost主机和端口8761上运行,因此我尝试通过以下方式更改此默认配置:
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
在我的客户端中,同样的事情发生了,我无法指向其他不同于默认设置的ureka服务器(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
答案 0 :(得分:2)
我使用了与您相同的依赖版本,并且找不到配置路径 server.servlet.contextpath
相反,您可以使用 server.servlet-path 或 server.context-path
对于每种服务器配置,您也需要更新客户端application.yml文件。请记住,/ eureka是用于向Eureka服务器注册Eureka客户端的默认REST端点。
情况1:使用 server.servlet-path
Eureka服务器:
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
Eureka服务器:
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一样保留。