由于配置中心一些信息比较敏感,这就要求我们做点安全保护处理。由于微服务是构建在Spring Boot之上,所以整合Spring Security是最方便的方式。
第一步:在config-server服务注入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
第二步:application.properties文件中添加用户名和密码
spring.security.user.name=security
spring.security.user.password=123456
第三步:在全部config-client配置文件添加用户名和密码即可
spring:
cloud:
config:
name: childdream-service
profile: dev
discovery:
service-id: config-server
enabled: true
#configserver安全配置
username: security
password: 123456
main:
allow-bean-definition-overriding: true
eureka:
client:
service-url:
defaultZone: http://eureka.didispace.com/eureka/