zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    简单使用GDB
    【老人孟岩经验谈】如何学习一本新的编程语言
    【做存档】如何争取到真正有用的人脉?
    回头来看C语言里的static
    Spring MVC 教程,快速入门,深入分析[1220]
    eclipse ibabis代码生成插件abator功能扩展
    在MyEclipse中配置Tomcat服务器
    将远程调试的控制台信息输出至Eclipse
    LOG4J.PROPERTIES配置详解
    java Map 怎么遍历
  • 原文地址:https://www.cnblogs.com/shiguotao-com/p/10420596.html
Copyright © 2011-2022 走看看