服务器端:
pom.xml添加的spring security
启动类添加了@EnableEurekaServer注解
yml如下
spring:
security:
user:
name: user
password: psw123
eureka:
client:
service-url:
defaultZone: http://user:psw123@localhost:8761/eureka
register-with-eureka: false
fetch-registry: false
客户端
pom添加spring-boot-starter-actuator依赖
启动类添加了@EnableDiscoveryClient注解
yml如下
eureka:
client:
service-url:
defaultZone: http://user:psw123@localhost:8761/eureka
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
服务器端启动正常,输入ip后也能通过输入用户名密码登录。但是客户端启动则报错。
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
如果去掉spring security验证的话客户端是能够正常注册到注册中心的。
网上服务器的yml配置(如下),我这里是没有的。我这里只有spring.security,
没有直接就security。
security:
basic:
enable:true
name:
password