黑马十次方项目day08-09 搭建配置中心微服务

版权声明:欢迎关注我的微信公众号 java持续实践,获取最新学习资料 https://blog.csdn.net/qq_33229669/article/details/87895155

一. 创建配置中心微服务

创建工程模块 配置中心微服务 tensquare_config ,pom.xml引入依赖

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

二.创建启动类

创建启动类ConfigServerApplication

package com.tensquare.config;

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

/**
 * 类名称:ConfigApplication
 * 类描述: 配置中心的启动类
 * @author: taohongchao
 * 创建时间:2019/2/23 17:53
 * Version 1.0
 */

@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {

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

三.编写配置文件application.yml

内容如下图
注意: 如果在码云上创建的是私有项目, 那么需要在yml中写上码云登录的用户名和密码,该配置中心才能从码云代码仓库中,获取配置

四.配置中心微服务获取配置文件测试

启动tensquare_config 项目, 开启的端口为12000.
在浏览器中输入如下的地址
http://localhost:12000/base-dev.yml
页面的内容如下,可以看到成功获取了配置文件.

猜你喜欢

转载自blog.csdn.net/qq_33229669/article/details/87895155