实现Eureka认证
导入依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>
编写config配置类
@EnableWebSecuritypublic class WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {// 忽略掉/eureka/**http.csrf().ignoringAntMatchers("/eureka/**");super.configure(http);}}
编写配置文件
# 指定用户名和密码spring:security:user:name: rootpassword: root
其他服务想注册到Eureka上需要添加用户名和密码
eureka:client:service-url:defaultZone: http://用户名:密码@localhost:8761/eureka
