springboot springcloud 配置中心

1.服务器端

2.客户端

1.服务器端

1.依赖+配置+启动注解

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
server.port=12000
spring.application.name=demo-config
#eureka配置
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:6868/eureka/
eureka.instance.prefer-ip-address=true
#config配置
spring.cloud.config.server.git.uri=https://gitee.com/ligenyun/demo-config.git

package com.ligy.school.config;

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

@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class ConfigMain {
    public static void main(String[] args) {
        SpringApplication.run(ConfigMain.class);
    }
}

ps:https://gitee.com/ligenyun/demo-config.git

这个地址,是码云的一个仓库地址;

配置后访问地址:localhost:12000/application-dev.properties

 

2.客户端

1.依赖+配置

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

bootstrap.properties

这里配置服务器端

spring.cloud.config.name=student
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.uri=http://localhost:12000

 

 

天生我材必有用,千金散尽还复来
原文地址:https://www.cnblogs.com/ligenyun/p/15810915.html