Spring Config:无法找到Config服务器

时间:2018-07-12 08:10:55

标签: spring spring-cloud-config spring-config

配置服务器spider network

bootstrap.yml

保险柜机密:

spring:
  application:
    name: configserver

  profiles:
    active: vault

  cloud:
    config:
      server:
        vault:
          host: ${vault_server_host:localhost}
          port: ${vault_server_port:8200}
          scheme: ${vault_server_scheme:https}
          backend: ${vault_backend:configserver}

因此,我可以使用$ vault kv get configserver/configclient === Data === Key Value --- ----- foo VAUUULT 获取配置值:

curl

因此,我尝试从Config客户端从Config服务器获取$ curl -X GET http://localhost:8888/configclient/default -H "X-Config-Token: f7b238dd-425f-52f8-2104-1e37ecf65ede" { "name":"configclient", "profiles":[ "default" ], "label":null, "version":null, "state":null, "propertySources":[ { "name":"vault:configclient", "source":{ "foo":"VAUUULT" } } ] } 值。配置客户端foo

bootstrap.yml

但是,似乎配置客户端无法找到配置服务器:

spring:
  application:
    name: configclient
  cloud:
    config:
      uri: http://localhost:8888
      headers:
        X-Config-Token: ${vault_token}

那么,这让我明白了

  

原因:java.lang.IllegalArgumentException:无法解析值“ $ {foo}”中的占位符“ foo”

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.3.RELEASE) 2018-07-12 10:03:53.809 INFO 15448 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888 2018-07-12 10:03:54.239 WARN 15448 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 400 null 2018-07-12 10:03:54.256 INFO 15448 --- [ main] c.t.i.t.s.t.TdevConfigclientApplication : No active profile set, falling back to default profiles: default 被配置为foo

@Value("${foo}")

在这里,您可以看到更详细的配置客户端跟踪代码段:

@SpringBootApplication
@RestController
public class TdevConfigclientApplication {

    @RequestMapping("/")
    public String home() {
        return "Hello World! " + this.foo;
    }

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

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

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在bootstrap.yml中,您需要用以下内容替换spring.cloud.config.headers:

spring:
  application:
    name: configclient
  cloud:
    config:
      uri: http://localhost:8888
      token : ${vault_token}

您可以看到文档http://cloud.spring.io/spring-cloud-config/1.4.x/single/spring-cloud-config.html