'Spring Cloud Config does not fetch config files
I just upgraded our spring boot projects to v2.6.2 from boot and 2021.0.0 from spring cloud.
And now nothing of my remote configuration fetching works, and the app does not fetch the correct property file
[main] INFO o.s.c.c.c.ConfigServicePropertySourceLocator - Fetching config from server at : http://localhost:8080
[main] WARN o.s.c.c.c.ConfigServicePropertySourceLocator - Could not locate PropertySource: Could not extract response: no suitable HttpMessageConverter found for response type [class org.springframework.cloud.config.environment.Environment] and content type [text/html;charset=UTF-8]
[main] INFO eu.hermes.esb.cloud.Application - No active profile set, falling back to default profiles: default
[main] INFO o.s.b.c.config.ConfigDataLoader - Fetching config from server at : http://localhost:8080
[main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data JPA repositories in DEFAULT mode.**
we use spring cloud config based on git repo that is filled with our config yml files in the following structures.
- app-one-dev.yml
- app-one-prod.yml
- app-two-dev.yml
- app-two-prod.yml and so on
I tried adding these two dependencies to the client service as suggested by some answers but nothing worked.
- spring-cloud-starter-config
- spring-cloud-starter-bootstrap
this is my config service yml:
spring.cloud.config.server:
git:
uri: https://bitbucket-prod.doa.otc.hlg.de/scm/inp-cloud/esb-spring-boot-config.git
username: foo
password: bar
force-pull: true
spring.security:
basic:
enabled: true
user:
name: inp
password: hermes
and my app runs with these properties:
-Dspring.config.import=configserver:http://inp:hermes@localhost:8080
-Dspring.cloud.config.name=esb-config-service
-Dspring.cloud.config.username=foo
-Dspring.cloud.config.username=bar
-Dspring.application.name=app-one
-Dspring.profiles.active=dev,console,gelf
our services run on Kubernetes in OKD. but I replicated the same situation locally on a windows machine so I do not think it is an environment specific.
Solution 1:[1]
The problem is most likely wrong credentials, i.e. username and password, in the client configuration.
It's hard to say for sure with the information provided. In particular, as the credentials given in the question are probably anonymized. But please note that in the given config snippet, you set the username twice and not the password. Furthermore, the snippet for the server config is not correctly indented. The properties for the client should probably contain
-Dspring.config.import=configserver:http://localhost:8080
-Dspring.cloud.config.username=inp
-Dspring.cloud.config.username=hermes
Spring Boot's auto-configuration of Spring Security is not a perfect match for the Spring Cloud Config Server. The problem is that the server forwards to the login page when the default Accept Header of the config client is sent with bad credentials. That's why the config client receives a response body with media type HTML, which the client does not understand.
Please double-check the credentials in your configuration. The most straight-forward method to prevent the problem in the future is to disable the login page in the config server, if you don't need it. Then you get a clear log message in the client for bad credentials.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
