Springboot搭建Eureka並設置Eureka登錄賬號密碼
一.創建一個springboot項目
1.可以使用Spring Initializr,用瀏覽器打開http://start.spring.io
2.在IntelliJ IDEA里創建新的Spring Boot應用程序,在File菜單里選擇New > Project選擇Spring Initializr
二.導入相應的maven依賴
此處為springboot的eureka相關依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
此處為設置eureka加解密security的相關依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
具體配置如下圖所示

三.啟動類上加入@EnableEurekaServer注解
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
super.configure(http);
}
}

四.修改配置文件
server.port: 8028
spring.application.name:demo-eureka
eureka.instance.hostname=127.0.0.1
#禁用將自己作為客戶端注冊,禁用客戶端注冊行為
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
#eureka地址
eureka.client.service-url.defaultZone=http://demo:123abcd@${eureka.instance.hostname}:${server.port}/eureka
#eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka
#關閉自我保護 --本地開發環境可以關閉,生產環境
eureka.server.enable-self-preservation = false
#清理節點時間
eureka.server.eviction-interval-timer-in-ms = 60000
spring.security.basic.enabled =true
spring.security.user.name =demo
spring.security.user.password =123abcd

五.啟動項目,登錄eureka
打開瀏覽器時,訪問eureka服務時出現此登錄界面,輸入配置文件中的整好的賬號密碼即可登錄spring.security.user.name =demo
spring.security.user.password =123abcd
github項目地址:https://github.com/Guns-Roses/demo-erurka

