Spring Cloud Config: client doesn't attempt to connect to the config server

你离开我真会死。 提交于 2021-01-28 05:07:18

问题


I'm trying to create a simple Spring Cloud Config server/client setup and am loosely following the documentation:

https://cloud.spring.io/spring-cloud-config/reference/html/

I've so far implemented a server that seems to work correctly, i.e. return the correct property values when I call the corresponding endpoint:

GET http://localhost:8888/config-client/development

{
  "name": "config-client",
  "profiles": [
    "development"
  ],
  "label": null,
  "version": null,
  "state": null,
  "propertySources": [
    {
      "name": "classpath:/config/config-client-development.properties",
      "source": {
        "user.role": "Developer"
      }
    }
  ]
}

I'm, however, not having any luck with getting the client to connect to the server. I have done the following:

  1. Added the spring-cloud-starter-config dependency:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
  1. Added a bootstrap.properties file:
spring.application.name=config-client
spring.profiles.active=development
spring.cloud.config.uri=http://localhost:8888

But I'm still getting a

java.lang.IllegalArgumentException: Could not resolve placeholder 'user.role' in value "${user.role}"

when trying to run the client application.

There is nothing in the application log that even looks like the client is attempting to communicate with the configuration server.

Link to a minimal GitHub repository that reproduces the issue: https://github.com/Bragolgirith/spring-cloud-minimal

Steps to reproduce:

  1. Build and run the config-service application
  2. Build and run the config-client application

Any idea what I'm doing wrong?


回答1:


OK, mistery solved.

It seems a new Spring Cloud version was released a week ago (https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available) that has a new way to activate the bootstrap process - now it doesn't happen by default, but requires adding an additional dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

Although this new version is now the default you get when using the Spring Initializr, the documentation is still not updated to reflect the changes - they are only briefly mentioned in the release notes.

As an alternative to using the new spring-cloud-starter-bootstrap dependency and a bootstrap.properties file, it seems the following is now also possible:

application.properties

spring.application.name=config-client
spring.profiles.active=development
spring.config.import=configserver:http://localhost:8888


来源:https://stackoverflow.com/questions/64836981/spring-cloud-config-client-doesnt-attempt-to-connect-to-the-config-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!