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
可正常注册
转载于:https://blog.51cto.com/786678398/1948060