【问题标题】:Spring Cloud Config does not fetch config filesSpring Cloud Config 不获取配置文件
【发布时间】:2022-01-30 12:52:47
【问题描述】:

我刚刚将我们的 Spring Boot 项目升级到 v2.6.2 from boot2021.0.0 from spring cloud

现在我的远程配置获取没有任何效果,并且应用程序没有获取正确的属性文件

[main] INFO o.s.c.c.c.ConfigServicePropertySourceLocator - 从服务器获取配置:http://localhost:8080

[main] WARN o.s.c.c.c.ConfigServicePropertySourceLocator - 找不到 PropertySource:无法提取响应:没有找到适合响应类型 [class org.springframework.cloud.config.environment.Environment] 和内容类型 [text/html;charset] 的 HttpMessageConverter =UTF-8]

[main] INFO eu.hermes.esb.cloud.Application - 未设置活动配置文件,回退到默认配置文件:默认

[main] INFO o.s.b.c.config.ConfigDataLoader - 从服务器获取配置:http://localhost:8080

[main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - 在默认模式下引导 Spring Data JPA 存储库。**

我们使用基于 git repo 的 spring cloud config,它在以下结构中填充了我们的配置 yml 文件。

  • app-one-dev.yml
  • app-one-prod.yml
  • app-two-dev.yml
  • app-two-prod.yml 等等

我尝试按照一些答案的建议将这两个依赖项添加到客户端服务,但没有任何效果。

  1. spring-cloud-starter-config
  2. spring-cloud-starter-bootstrap

这是我的配置服务 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

我的应用程序使用以下属性运行:

-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

我们的服务在 OKD 的 Kubernetes 上运行。但我在 Windows 机器上本地复制了相同的情况,所以我认为它不是特定于环境的。

【问题讨论】:

    标签: spring-boot spring-cloud java-11 spring-cloud-config


    【解决方案1】:

    问题很可能是客户端配置中的错误凭据,即用户名和密码。

    根据所提供的信息很难确定。特别是,由于问题中给出的凭据可能是匿名的。但请注意,在给定的配置 sn-p 中,您设置了两次用户名而不是密码。此外,服务器配置的 sn-p 没有正确缩进。客户端的属性可能应该包含

    -Dspring.config.import=configserver:http://localhost:8080
    -Dspring.cloud.config.username=inp
    -Dspring.cloud.config.username=hermes
    

    Spring Boot 对 Spring Security 的自动配置并不是 Spring Cloud Config Server 的完美匹配。问题是当配置客户端的默认 Accept Header 发送带有错误凭据时,服务器会转发到登录页面。这就是为什么配置客户端会收到一个媒体类型为 HTML 的响应正文,客户端不理解。

    请仔细检查您的配置中的凭据。防止将来出现问题的最直接方法是禁用配置服务器中的登录页面,如果您不需要它。然后,您会在客户端中收到一条清晰的日志消息,说明凭据错误。

    【讨论】:

      猜你喜欢
      • 2018-03-22
      • 2022-12-04
      • 2017-02-23
      • 1970-01-01
      • 2023-02-15
      • 2017-10-12
      • 2021-01-29
      • 2015-08-25
      • 2019-03-20
      相关资源
      最近更新 更多