springcloud 使用Config Client

版权声明:本文为博主原创文章,未经博主允许不得转载(转载请声明原文地址,谢谢java交流群:553997290) https://blog.csdn.net/qq_39313596/article/details/83658702

根据上一篇文章:https://blog.csdn.net/qq_39313596/article/details/83657785接着使用Config Client 

在你要引入配置文件的地方加入jar

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

启动类

package com.hlvy.order;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
public class OrderApplication {

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

接着把配置文件改为bootstrap.yml优先启动

配置文件代码:

server:
  port: 9092
spring:
  application:
    name: order
  cloud:
    config:
      discovery:
        enabled: true
        #CONFIG是注册中心config项目配置注册的名字
        service-id: CONFIG  
      profile: dev

接着启动就ok了

猜你喜欢

转载自blog.csdn.net/qq_39313596/article/details/83658702