我有一个在默认的localhost主机和端口8761上运行的Eureka服务器,所以我试图以这种方式更改此默认配置:
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
Eureka客户:
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
Eureka客户:
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中。