zoukankan      html  css  js  c++  java
  • 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 加进来即可

     显示结果

    @

    -------博客内容仅用于个人学习总结-------
  • 相关阅读:
    Notes about "Exploring Expect"
    Reuse Sonar Checkstyle Violation Report for Custom Data Analysis
    Eclipse带参数调试的方法
    MIT Scheme Development on Ubuntu
    Manage Historical Snapshots in Sonarqube
    U盘自动弹出脚本
    hg的常用配置
    Java程序员的推荐阅读书籍
    使用shared memory 计算矩阵乘法 (其实并没有加速多少)
    CUDA 笔记
  • 原文地址:https://www.cnblogs.com/DarGi2019/p/11775046.html
Copyright © 2011-2022 走看看