1.eureka服务端(注册中心)添加以下配置
在pom文件添加依赖
1
2
3
4
|
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
|
更改yum文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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.服务提供方添
如果按照前的方式启动,比如下面配置
1
2
3
4
|
eureka:
client:
serviceUrl:
defaultZone: http:
//localhost:1000/eureka/
|
会报错
1
|
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
|
所以配置更改为
1
2
3
4
|
eureka:
client:
serviceUrl:
defaultZone: http:
//admin:admin123@localhost:1000/eureka
|
可正常注册
本文转自gaofeng36599 51CTO博客,原文链接:http://blog.51cto.com/786678398/1948060