1. Introduce dependencies in the pom file
Add spring-security support
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2. The application.yml file adds the user name and password configuration for management
2.1 Add spring.security configuration
spring:
security:
basic:
enabled: true
user:
name: eureka
password: eureka
2.2 Modify eureka.client.serviceUrl.defaultZone to add account password
http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
2.3 The modified complete application.yml is:
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/