springcloud系列27——Spring Cloud Config之Security

Config Server端

1.添加spring-boot-starter-security依赖

<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-securityartifactId>
dependency>

2.在配置文件配置用户名和密码

security:
  basic:
    enabled: true
  user:
    # 默认为user
    name: user
    password: password123

security.basic.enabled默认为true,security.user.name默认为user,security.user.password默认是随机生成的一串文字,在启动的时候从控制台可以看到。

然后在访问Config Server时会要求输入用户名和密码。

输入上面配置文件中配置的用户名和密码后就可以访问了。

Config Client端

config server端增加认证后,config client也需要做一定的配置。

有2种方式配置用户名和密码。

第1种方式:

spring.cloud.config.username=user
spring.cloud.config.password=password123

第2种方式:

spring.cloud.config.uri=http://user:[email protected]:${config.port:8888}

PS:如果这2种方式都配置了,生效的是第1种方式。

你可能感兴趣的:(Spring,Cloud,SpringCloud入门)