引入依赖
要启用 Eureka Server 的安全认证,需要先引入一下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
增加 Spring Security 配置类
/**
* @Author:大漠知秋
* @Description:Spring Security 配置
* @CreateDate:2:54 PM 2018/10/23
*/
@Configuration
public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
// 关闭 CSRF
http.csrf().disable();
}
}
增加配置信息
spring:
# 开启安全控制
security:
user:
# 用户名
name: eureka-server
# 密码
password: eureka-server
Eureka Client 配置
配置文件
增加一下配置
### 注册中心配置
eureka:
client:
security:
user:
name: eureka-server
password: eureka-server
# Spring Cloud Eureka 注册中心地址
service-url:
defaultZone: http://${eureka.client.security.user.name}:${eureka.client.security.user.password}@${eureka.instance.hostname}:8761/eureka/
文章转载 主要是为记住
原地址: https://blog.csdn.net/wo18237095579/article/details/83307214