首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring云配置客户端之间的共享配置

Spring云配置客户端之间的共享配置
EN

Stack Overflow用户
提问于 2016-03-02 14:11:00
回答 1查看 1.2K关注 0票数 5

我试图在Spring客户端与Spring配置服务器之间共享配置,Spring配置服务器有一个基于文件的存储库:

代码语言:javascript
复制
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

// application.yml
server:
  port: 8888

spring:
  profiles:
    active: native

test:
  foo: world

我的Spring客户机之一使用配置服务器中定义的test.foo配置,配置如下:

代码语言:javascript
复制
@SpringBootApplication
@RestController
public class HelloWorldServiceApplication {

    @Value("${test.foo}")
    private String foo;

    @RequestMapping(path = "/", method = RequestMethod.GET)
    @ResponseBody
    public String helloWorld() {
        return "Hello " + this.foo;
    }

    public static void main(String[] args) {
        SpringApplication.run(HelloWorldServiceApplication.class, args);
    }
}

// boostrap.yml
spring:
  cloud:
      config:
        uri: ${SPRING_CONFIG_URI:http://localhost:8888}
      fail-fast: true

// application.yml
spring:
  application:
    name: hello-world-service

尽管有这种配置,Spring客户机中的Environment不包含test.foo条目(cf java.lang.IllegalArgumentException: Could not resolve placeholder 'test.foo')

但是,如果我将这些属性放在基于配置服务器文件的存储库中的hello-world-service.yml文件中,那么它就能很好地工作。

Maven对Spring Brixton.M5和SpringBoot1.3.3的依赖关系。3.使用spring-cloud-starter-configspring-cloud-config-server的Brixton.M5

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-02 16:09:53

来自弹簧云文档

对于“本机”配置文件(本地文件系统后端),建议您使用不属于服务器自身配置的显式搜索位置。否则,默认搜索位置中的应用程序*资源将被删除,因为它们是服务器的一部分。

因此,我应该将共享配置放在外部目录中,并将路径添加到config-serverconfig-server文件中。

代码语言:javascript
复制
// application.yml
spring:
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: file:/Users/herau/config-repo

// /Users/herau/config-repo/application.yml
test:
  foo: world
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35749567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档