為什么學習SpringCloud? SpringCloud是基於SpringBoot,提供了完整的微服務解決方案,包含了眾多組件,是目前很火的微服務框架。
選擇的編輯器IDEA 那么開始吧^^*:
1.創建父項目

選maven->next

取個名

現頁面:

2.Eureka server


取個名字

請選擇 Eureka Server

這個不用改

finish->

改成了yml文件
代碼:
spring: application: name: eureka-server security: user: name: user password: 123456 server: port: 8890 eureka: client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://user:123456@localhost:8890/eureka/ server: renewalPercentThreshold: 0.49

加注解 @EnableEurekaServer

debug 啟動測試一下:

瀏覽器頁面測試:

讓賬號密碼起作用:+
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
展示結果

***當加了密碼之后起client 起不來時:
package com.cloud.eurekaserver.config; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class WebSecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception { http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER); http.csrf().disable(); http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); } }

