1. pom 文件中引入依赖

添加spring-security支持

        <dependency>
		   <groupId>org.springframework.boot</groupId>
		   <artifactId>spring-boot-starter-security</artifactId>
		</dependency>

2. application.yml 文件增加管理的用户名密码配置

2.1 增加 spring.security 配置

spring:
  security:
    basic:
      enabled: true
    user:
      name: eureka
      password: eureka

2.2 eureka.client.serviceUrl.defaultZone 修改,增加账号密码

http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

2.3 修改后的完整的 application.yml 为:

server:
  port: 8081

spring:
  security:
    basic:
      enabled: true
    user:
      name: eureka #登录账号
      password: eureka #登录密码

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
05-23 17:57