配置中心config,直接访问远端yml文件为空?

首先回顾一下config的服务端的配置方法:
1.导包

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

2.启动类写上@EnableConfigServer
3.配置yml文件

server:
  port: 8090
spring:
  application:
    name: config-demo
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/liaochaoxxx/configuration_file.git
      这样就可以启动并通过:http://localhost:8090/common-dev.yml去访问到common-dev.yml文件

注意这里有坑:我访问了很久返回都是空找不到原因,后来发现

spring:
  application:
    name: lpp-config  #服务名称
 profiles:
    active: native  # 配置使用本地储存

#这里注意:
profiles:
active: native # 配置使用本地储存
它只在本地访问,不去远端。所以访问不了。
如果测试的时候把配置文件放在本地文件夹,就需要配置这个。
如果去远端(gitee)上时就需要删除这个,否则访问不通
还有:要保证远端(gitee)上的内容是public的

发布了67 篇原创文章 · 获赞 12 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/m0_37635053/article/details/103489934