Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring cloud Spring云配置客户端未从配置服务器拾取值_Spring Cloud_Configserver_Spring Cloud Config Server - Fatal编程技术网

Spring cloud Spring云配置客户端未从配置服务器拾取值

Spring cloud Spring云配置客户端未从配置服务器拾取值,spring-cloud,configserver,spring-cloud-config-server,Spring Cloud,Configserver,Spring Cloud Config Server,我的配置客户端没有从配置中拾取属性值 服务器 上面的配置服务器终结点正在为配置客户端返回正确的值 { "name": "customer_service", "profiles": [ "default" ], "label": null, "version": "c7648db5662dc65aeaad9c91abbf58b41010be7c", "state": null, "propertySources": [

我的配置客户端没有从配置中拾取属性值 服务器

上面的配置服务器终结点正在为配置客户端返回正确的值

{
    "name": "customer_service",
    "profiles": [
        "default"
    ],
    "label": null,
    "version": "c7648db5662dc65aeaad9c91abbf58b41010be7c",
    "state": null,
    "propertySources": [
        {
            "name": "https://github.com/prasadrpm/MicroService_config.git/customer_service.properties",
            "source": {
                "customer.config.location": "XXXX",
                "customer.config.name": "YYYY"
            }
        }
    ]
}
Config client bootstrap.properties

server.port=8080
spring.application.name=customer_service

spring.cloud.config.enabled=true
spring.cloud.config.name=config_server
spring.cloud.config.uri=http://localhost:8888
配置客户端日志

2020-04-10 16:47:00.725  INFO 14976 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-04-10 16:47:03.267  INFO 14976 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config_server, profiles=[default], label=null, version=c7648db5662dc65aeaad9c91abbf58b41010be7c, state=null
2020-04-10 16:47:03.269  INFO 14976 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}]
2020-04-10 16:47:03.280  INFO 14976 --- [           main] com.customer.CustomerServiceApplication  : No active profile set, falling back to default profiles: default
...
2020-04-10 16:47:05.164  INFO 14976 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1860 ms
2020-04-10 16:47:05.549  WARN 14976 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'customer.config.location' in value "${customer.config.location}"
2020-04-10 16:47:05.552  INFO 14976 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-04-10 16:47:05.577  INFO 14976 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-10 16:47:05.595 ERROR 14976 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'customer.config.location' in value "${customer.config.location}"
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]

返回正确属性/配置的URL为:
localhost:8888/customer\u service/default

客户端应用程序正在根据以下数据查询属性:

c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config_server, profiles=[default], label=null, version=c7648db5662dc65aeaad9c91abbf58b41010be7c, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}]
com.customer.CustomerServiceApplication  : No active profile set, falling back to default profiles: default
...
因此,客户端应用程序实际上正在调用:

localhost:8888/config_server/default 
因此,有两种解决方案:

  • 删除bootstrap.properties中的
    spring.cloud.config.name=config\u server
    属性,应用程序应该能够获取属性
  • spring.cloud.config.name的值更新为
    customer\u service
    service。但如果您没有明确提供
    spring.cloud.config.name
    ,那么客户端将使用
    spring.application.name
    作为
    spring.cloud.config.name
    的默认值

    • 您在这里使用了什么注释? 它可以像这样轻松地检索

      @Value("${customer.config.location}")
          private String someOtherProperty;
      
      这是不需要的

      spring.cloud.config.name=config\u服务器


      我只是使用完全相同的注释@值(“${customer.config.location}”)私有字符串位置@你能在你试图检索控制器的地方分享它的代码片段吗?
      @Value("${customer.config.location}")
          private String someOtherProperty;