Eureka注册中心:
1.pom.xml增加依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.配置文件:application.yml
spring:
profiles: jielong
security:
basic:
enabled:true
user:
name: user1
password: password123
3.开启认证
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//开启认证
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
http.csrf().ignoringAntMatchers("/eureka/**");
super.configure(http);
}
}
4.应用客户端配置文件:application.yml
eureka:
client:
serviceUrl:
defaultZone: http://user1:password123@localhost:9030/eureka/
5.登录控制台:(某些浏览器不支持直接登录)
http://user1:password123@localhost:9030/
或
http://localhost:9030/
输入账号和密码;