java1234开源博客系统
博客信息

Config Server基本使用

0
发布时间:『 2019-03-04 16:22』  博客类别:SpringCloud  阅读(5005) 评论(0)

Config Server基本使用


根据前面SpringCloud架构图,首先第一步,要搞个 configServer来联通远程GIT仓库,来读取远程配置;


这里GIT仓库,我们一般选用GitHub https://github.com/,或者码云  https://gitee.com/  

我们课程用GitHub演示,首先大伙去GitHub注册个账号,


建个仓库 microservice-config  然后 Git下载本地;


上传一个配置文件上到git仓库,application.yml 记住要utf-8编码,否则乱码,解析各种问题;


文件内容:

profile: hello


QQ鎴浘20190304155039.jpg

随便搞,目前只要能读取到配置即可;


新建module:microservice-config-server-4001


引入依赖:

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-config-server</artifactId>
</dependency>


启动类ConfigServerApplication_4001:

package com.java1234;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication_4001 {

	public static void main(String[] args) {
		SpringApplication.run(ConfigServerApplication_4001.class, args);
	}
}


这里要加下注解:@EnableConfigServer


这里我们搞下仓库的Http地址:

QQ鎴浘20190304160318.jpg



然后项目的application.yml配置下:

server: 
  port: 4001 
  
spring:
  application:
    name:  microservice-config
  cloud:
    config:
      server:
        git:
          uri: https://github.com/java1234/microservice-config


主要是要配置一个git请求地址:


本地Hosts加个本地域名映射:

127.0.0.1  configserver.java1234.com


然后我们本地请求:http://configserver.java1234.com:4001/application-xx.yml


返回结果了正确的文本结果;


至于请求路径,有匹配规则:

The HTTP service has resources in the form:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties




关键字:   Config     Server基本使用  
关注Java1234微信公众号
博主信息
Java1234_小锋
(知识改变命运,技术改变世界)
Powered by Java1234 V3.0 Copyright © 2012-2016 Java知识分享网 版权所有