我們需要引入的依賴包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
然後需要在配置文件中增加的配置:
spring:
security:
user:
name: root
password: jack66666
最後我們需要增加一個配置類:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
// super.configure(http);
http.csrf().disable();
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
}
啓動項目成功後我們訪問Eureka的管理界面需要認證。
這時候就需要輸入用戶名和密碼去訪問了。
同理我們服務端往Eureka註冊也是需要添加認證信息的
spring:
security:
user:
name: root
password: jack66666