首先需要在需要的项目中引入依赖
<!--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服务。依次启动。
就可以拿到配置文件。但是还是实现不了(不需要启动服务自动更新配置文件)