好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

spring cloud 配置中心native配置方式

spring cloud 配置中心native配置

1、pom文件添加依赖

?

1

2

3

4

< dependency >

     < groupId >org.springframework.cloud</ groupId >

     < artifactId >spring-cloud-config-server</ artifactId >

</ dependency >

2、配置文件application.properties中配置本地路径

?

1

2

3

4

5

6

#tomcat端口号

server.port= 8001

#配置文件在本地

spring.profiles.active= native

#配置文件的目录

spring.cloud.config.server. native .search-locations=D:/workspace/GitHub/spring-config/config-file

3、主程序开启@EnableConfigServer注解

?

1

2

3

4

5

6

7

@EnableConfigServer

@SpringBootApplication

public class ConfigApplication {

public static void main(String[] args) {

     SpringApplication.run(ConfigApplication. class , args);

     }

}

spring config server 使用native

使用spring cloud的config server,在config server中存放一份默认的配置文件,文件位于应用的resouces中,位置是 resource/shared,将随config server打包一同发布

在追加一个文件系统的位置,这个位置中可以存放自定义的配置信息,系统部署后,可在约定的这个文件夹中自定义配置文件config server对外提供配置服务的yml文件,其中application.yml将向所有config client提供配置参数然后还有具体的application配置文件 appname.yml每个系统有两个配置文件,加上两个配置文件存放位置,

因此,一个系统的配置文件会加载四个yml文件四个yml配置文件中,优先级高的配置会覆盖优先级低的配置文件假如config 的client是park-auth,对应的配置文件分别为(配置项优先级从高到低排列):

/var/park/conf/park-auth.ymlclasspath:/shared/park-auth.yml/var/park/conf/application.ymlclasspath:/shared/application.ymlconfig server的native配置

优先级高的配置在下面 cloud: config: server: native: search-locations: - classpath:/shared - /var/park/conf

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://blog.csdn.net/zhang_zining/article/details/79081302

查看更多关于spring cloud 配置中心native配置方式的详细内容...

  阅读:12次