实现Eureka认证
    导入依赖

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-security</artifactId>
    4. </dependency>

    编写config配置类

    1. @EnableWebSecurity
    2. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    3. @Override
    4. protected void configure(HttpSecurity http) throws Exception {
    5. // 忽略掉/eureka/**
    6. http.csrf().ignoringAntMatchers("/eureka/**");
    7. super.configure(http);
    8. }
    9. }

    编写配置文件

    1. # 指定用户名和密码
    2. spring:
    3. security:
    4. user:
    5. name: root
    6. password: root

    其他服务想注册到Eureka上需要添加用户名和密码

    1. eureka:
    2. client:
    3. service-url:
    4. defaultZone: http://用户名:密码@localhost:8761/eureka