1.eureka服務端(註冊中心)添加以下配置
在pom文件添加依賴
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-security</artifactId> </dependency>
更改yum文件
server: port: 1000 eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://admin:admin123@localhost:1000/eureka spring: application: name: eureka-server security: basic: enabled: true user: name: admin password: admin123
security中的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
可正常註冊