SpringCloud学习笔记-统一配置中-SpringCloud-Config-client

 

首先需要在需要的项目中引入依赖

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

然后再修改配置文件 把 application.yml 修改成bootstrap.yml。

spring:
  application:
    name: order
  cloud:
    config:
      discovery:
        enabled: true
        service-id: CONFIG
      profile: test
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

修改文件名称是因为springBoot加载配置文件的顺序(先加载bootstrap.yml,再加载application.yml)

说明:http://www.cnblogs.com/EasonJim/p/7589546.html

然后修改git上面的文件order.yml与order-test.yml

因为在启动configServer的时候,会把这2个配置文件的内容合并全部去下来。所以可以把共同的配置内容放到order.yml文件里面。

order.yml

spring:
  application:
    name: order
  jpa:
    database-platform: org.hibernate.dialect.MySQLDialect
    show-sql: true  # jpa ????????????
server:
  port: 8088

order-test.yml

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: 123456
    url: jdbc:mysql://127.0.0.1:3306/SpringCloud?characterEncoding=utf-8&useSSL=false
env: test
label: master

order-dev.yml

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: 123456
    url: jdbc:mysql://127.0.0.1:3306/SpringCloud?characterEncoding=utf-8&useSSL=false
env: dev
package com.hx.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
@EnableFeignClients(basePackages="com.hx.order.client")
public class OrderApplication {

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

}
OrderApplication启动类需要这样。

启动eurekaServer服务、configServer服务,order服务。依次启动。
就可以拿到配置文件。但是还是实现不了(不需要启动服务自动更新配置文件)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值