可能出现的
服务端yml配置
#内置的 tomcat 服务启动监听端口号
server:
port: 8001
#应用名称
spring:
application:
name: EurekaServer01
#EurekaServer 配置
eureka:
client:
register-with-eureka: false #此 EurekaServer 不在注册到其他的注册中心
fetch-registry: false #不在从其他中心中心拉取服务器信息
service-url:
defaultZone: http://localhost:8001/eureka01/ #注册中心访问地址
客户端yml配置
server:
port: 9001
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/springcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: admin
application:
name: UserProvdier01
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka01/eureka/
问题:服务端客户端启动正常,客户端连接不了服务端
//出现问题
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
解决方法1
修改服务端yml配置,添加context-path,修改defaultZone
#内置的 tomcat 服务启动监听端口号
server:
port: 8001
servlet:
context-path: /eureka01
#应用名称
spring:
application:
name: EurekaServer01
#EurekaServer 配置
eureka:
client:
register-with-eureka: false #此 EurekaServer 不在注册到其他的注册中心
fetch-registry: false #不在从其他中心中心拉取服务器信息
service-url:
defaultZone: http://localhost:8001/ #注册中心访问地址
解决方法2
修改客户端端yml配置,修改defaultZone
server:
port: 9001
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/springcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: admin
application:
name: UserProvdier01
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
服务端根据yml中配置defaultZone的url不同,浏览器访问路的径也不同,测试ok