Spring配置:It';s无法找到配置服务器

Spring配置:It';s无法找到配置服务器,spring,spring-cloud-config,spring-config,Spring,Spring Cloud Config,Spring Config,配置服务器bootstrap.yml: spring: application: name: configserver profiles: active: vault cloud: config: server: vault: host: ${vault_server_host:localhost} port: ${vault_server_port:8200} sch

配置服务器
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}
spring:
  application:
    name: configclient
  cloud:
    config:
      uri: http://localhost:8888
      headers:
        X-Config-Token: ${vault_token}
金库机密:

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

$ 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: 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}
spring:
  application:
    name: configclient
  cloud:
    config:
      uri: http://localhost:8888
      headers:
        X-Config-Token: ${vault_token}
但是,配置客户端似乎无法定位配置服务器:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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
所以,这让我明白:

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

foo
配置为
@Value(${foo}”)

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

2018-07-12 10:29:05.249  INFO 17299 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2018-07-12 10:29:05.457 DEBUG 17299 --- [           main] o.s.web.client.RestTemplate              : Created GET request for "http://localhost:8888/configclient/default"
2018-07-12 10:29:06.023 DEBUG 17299 --- [           main] o.s.web.client.RestTemplate              : Setting request Accept header to [application/json, application/*+json]
2018-07-12 10:29:06.092 DEBUG 17299 --- [           main] s.n.www.protocol.http.HttpURLConnection  : sun.net.www.MessageHeader@3bb6b7e25 pairs: {GET /configclient/default HTTP/1.1: null}{Accept: application/json, application/*+json}{User-Agent: Java/10.0.1}{Host: localhost:8888}{Connection: keep-alive}
2018-07-12 10:29:06.121 DEBUG 17299 --- [           main] s.n.www.protocol.http.HttpURLConnection  : sun.net.www.MessageHeader@3b1892d05 pairs: {null: HTTP/1.1 400}{Content-Type: application/json;charset=UTF-8}{Transfer-Encoding: chunked}{Date: Thu, 12 Jul 2018 08:29:06 GMT}{Connection: close}
2018-07-12 10:29:06.145 DEBUG 17299 --- [           main] o.s.web.client.RestTemplate              : GET request for "http://localhost:8888/configclient/default" resulted in 400 (null); invoking error handler
2018-07-12 10:29:06.162  WARN 17299 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 400 null

有什么想法吗?

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

spring:
  application:
    name: configclient
  cloud:
    config:
      uri: http://localhost:8888
      token : ${vault_token}
你可以看医生