1.eureka服务端(注册中心)添加以下配置
在pom文件添加依赖
org.springframework.cloud spring-cloud-starter-security
更改yum文件
server: port: 1000eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://admin:admin123@localhost:1000/eurekaspring: application: name: eureka-serversecurity: basic: enabled: true user: name: admin password: admin123security中的name、password和service-url.defaultZone中地址的要一致
2.服务提供方添
如果按照前的方式启动,比如下面配置
eureka: client: serviceUrl: defaultZone: http://localhost:1000/eureka/
会报错
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
所以配置更改为
eureka: client: serviceUrl: defaultZone: http://admin:admin123@localhost:1000/eureka
可正常注册