Spring Cloud Consul配置无法识别键值存储中的其他文件

时间:2018-11-03 11:06:11

标签: java spring-boot consul spring-cloud-consul

在下面使用sample.xml成功读取资源getResourceAsStream中的文件。

@Value("${sample}")
private String sample;

InputStream is = this.getClass().getClassLoader().getResourceAsStream(sample);

resources / application.properties

sample=sample.xml

不过,在将application.propertiessample.xml外部化为 consul 之后,不再找到sample.xml。

还在日志中仅打印检测到application.properties,而不打印在myapp中也显示为myapp/application/sample.xml的sample.xml

b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='consul', propertySources=[ConsulFilesPropertySource {name='myapp/application/application.properties'}]}

所以剩下的唯一方法是从领事那里下载文件,然后打开一个输入流。我们不能在第一个示例中继续使用getResourceAsStream来使用外部文件进行咨询,就像从s resources目录中进行读取一样吗?

http://${spring.cloud.consul.host}:${spring.cloud.consul.port}/v1/kv/${spring.cloud.consul.config.prefix}/sample.xml?raw=true&xml

bootstrap.yml

spring:
  application:
    name: myapp
  cloud:
    consul:
      config:
        enabled: true
        format: files
        fail-fast: true
        prefix: myapp/application
      host: localhost
      port: 8500

0 个答案:

没有答案