2、撸一撸Spring Cloud - 创建Eureka注册中心

创建Eureka注册中心

本文需要对IDEA有一定的了解,清楚IDEA中项目与文件的创建,后续迭代补充基础知识

前期准备

  • 通过IDEA创建module dsz-eureka
  • 依赖项目dsz-root

Spring Cloud版本选型

  • Greenwich SR2
  • Spring Boot 2.1.6.RELEASE
  • Spring 5.1.8.RELEASE
  • jdk 1.8.0_172

最终展示pom.xml和项目结构

项目结构


项目结构

pom.xml



    
        dsz-root
        com.dsz.platform
        1.0-SNAPSHOT
    
    4.0.0

    dsz-eureka

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        

        
        
            org.springframework.boot
            spring-boot-starter-security
        
    


application.yml

server:
  port: 8761
spring:
  application:
    name: dsz-eureka
  security:
    user:
      name: admin
      password: admin
eureka:
  instance:
    hostname: 127.0.0.1
    ## 心跳间隔-5秒
    lease-renewal-interval-in-seconds: 5
    ## 没有心跳的淘汰时间-10秒
    lease-expiration-duration-in-seconds: 10
  client:
    ## 刷新本地缓存-5秒
    registry-fetch-interval-seconds: 5
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    ## 开发环境建议关闭自我保护
    enable-self-preservation: false
    ## 主动失效时间
    eviction-interval-timer-in-ms: 5000
    ## 不开启缓存
    use-read-only-response-cache: false
    ## 指定每分钟需要收到的续约次数的阈值
    renewal-percent-threshold: 0.85

com.dsz.base.eureka.EurekaApplication

package com.dsz.base.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

    public static void main(String[] args) {

        SpringApplication.run(EurekaApplication.class, args);

    }
}

com.dsz.base.eureka.security.WebSecurityConfig

package com.dsz.base.eureka.security;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().ignoringAntMatchers("/eureka/**");
        super.configure(http);
    }
}

下期预告《撸一撸Spring Cloud - 创建Config配置中心》

你可能感兴趣的:(2、撸一撸Spring Cloud - 创建Eureka注册中心)