我的版本信息:Spring Boot:2.2.1
SpringCloud:Hoxton.RELEASE
首先需要添加security的坐标
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
在注册中心的全局配置文件里开启安全验证,需添加如下代码:
#设置服务注册中心地址,指向另一个注册中心
eureka.client.serviceUrl.defaultZone=http://user:123123@eureka1:8761/eureka/
#用于安全登录的账号和密码
spring.security.user.name=user
spring.security.user.password=123123
SpringBoot2.X需要一个SpringSecurity配置类(放在Eureka注册中心)
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.spring