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 加进来即可

     显示结果

    @

    -------博客内容仅用于个人学习总结-------
  • 相关阅读:
    在SUSE12中使用 Machinery 进行高级系统管理
    有多个git项目要用多个秘钥
    Manage, Administrate and Monitor GlassFish v3 from Java code usingAMX &amp; JMX
    apc smart UPS下使用apcupsd注意事项
    Eclipse用法和技巧二十二:快速调整字体大小
    OpenGL(十三) Alpha测试、剪裁测试
    什么图用什么工具画?
    什么图用什么工具画?
    scipy —— 丰富的子包(io、cluster)
    scipy —— 丰富的子包(io、cluster)
  • 原文地址:https://www.cnblogs.com/DarGi2019/p/11775046.html
Copyright © 2011-2022 走看看