SpringCloud项目搭建(一) 父工程与Eureka server --从零开始

为什么学习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
View Code

  fetchRegistry: false #指定是否要从注册中心获取服务(注册中心不需要开启)

  registerWithEureka: false #指定是否要注册到注册中心(注册中心不需要开启)

  enableSelfPreservation: false #关闭保护模式

  renewalPercentThreshold:0.85 #默认为0.85 是触发自我保护机制的阀值

加注解  @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();
    }
}
View Code

 

*** 如何显示run Dashboard

第一步

 

 第二步 把Spring Boot 和 Application 加进来即可

 

 显示结果

 

 

@

posted @ 2020-01-13 17:17  DarGi  阅读(2361)  评论(0编辑  收藏  举报