• Eureka 使用Spring cloud config 管理中心启动


    Config 工程创建之后,Eureka就可以使用Git上的配置启动服务了。

     Git 服务器的搭建这里就不细说了(自行解决),下面是我上传再git的配置文件:

    创建EurekaServer项目(eureka-server):

    pom.xml

      <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
        </dependencies>

    配置启动类:

    @SpringBootApplication
    @EnableEurekaServer
    public class EurekaServerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaServerApplication.class, args);
        }
    
    }

    bootstrap.yml

    spring:
      application:
        name: eureka-server
      cloud:
        config:
          uri: http://127.0.0.1:9090

    这里Eureka配置开启了验证功能,spring security默认开启csrf校验,服务之间通讯并没有web页面,所以需要关闭:

    package com.eureka.server.util;
    
    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;
    
    @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            super.configure(http);
            http.csrf().disable();
        }
    }

    使用Git中的配置文件启动服务:

    需要使用--spring.profiles.active=peer2命令,peer2 是config中的profile

  • 相关阅读:
    一、docker安装CentOS7
    c#使用资源文件完成国际化
    .netcore 读取ansi编码
    省市区数据库
    .netcore2.0发送邮件
    使用py,根据日志记录自动生成周报
    mysql监控每一条执行的sql语句
    根据json生成c#实体类
    使用.net core efcore根据数据库结构自动生成实体类
    winform,同个程序只允许启动一次
  • 原文地址:https://www.cnblogs.com/shiguotao-com/p/10420596.html
Copyright © 2020-2023  润新知