gpt4 book ai didi

Spring Boot 云配置客户端未获取云配置,错误消息为 : no suitable HttpMessageConverter found?

转载 作者:行者123 更新时间:2023-12-05 02:01:46 40 4
gpt4 key购买 nike

我正在尝试将我的 Spring Boot 应用程序“config-test”连接到 Springframework 的云配置服务器。它没有获取应用程序的配置,而是回答错误并中止应用程序(因为 fail-fast 选项):

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]

连接到它说的配置服务器:

 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.0.RELEASE)

2021-02-21 17:41:32.950 INFO 1891 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8081
2021-02-21 17:41:33.230 ERROR 1891 --- [ main] o.s.boot.SpringApplication : Application run failed

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:148) ~[spring-cloud-config-client-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:52) ~[spring-cloud-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locateCollection(ConfigServicePropertySourceLocator.java:163) ~[spring-cloud-config-client-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:97) ~[spring-cloud-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:626) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:370) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at com.lhsystems.cdb.logging_test.DynamicConfigLogLevelApplication.main(DynamicConfigLogLevelApplication.java:24) [classes/:na]
Caused by: org.springframework.web.client.RestClientException: 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]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:123) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:998) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:981) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:741) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:583) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:264) ~[spring-cloud-config-client-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:107) ~[spring-cloud-config-client-2.2.2.RELEASE.jar:2.2.2.RELEASE]
... 9 common frames omitted

2021-02-21 17:41:33.234 WARN 1891 --- [ main] o.s.boot.SpringApplication : Unable to close ApplicationContext

我已经在“bootstrap.yml”属性文件中定义了云配置服务器的 URI。 bootstrap.yml 是:

spring:
cloud:
config:
name: config-test
uri: http://localhost:8081
fail-fast: true

logging:
level:
com.harry.potter.logging_test: trace

我有一个“application.properties”文件,用于在运行时启用配置客户端的/refresh 功能:

management.endpoints.web.exposure.include=*

我项目的 pom.xml 是:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.harry.potter</groupId>
<artifactId>cloud-aware-microservices</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>cloud-aware-microservices-config-test</artifactId>

<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

我项目的父 pom.xml 是:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<groupId>com.harry.potter</groupId>
<artifactId>cloud-aware-microservices</artifactId>
<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<name>cloud-aware-microservices</name>
<description>Cloud Aware Microservice Configuration System</description>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
<module>cloud-aware-microservices-config</module>
<module>cloud-aware-microservices-config-test</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

配置服务器按预期工作,当通过请求(使用 curl)激活时,返回组织为 GIT 存储库的本地文件的配置内容。

我做错了什么?

最佳答案

这里的问题是配置客户端在没有凭据(或错误的凭据)的情况下请求配置服务器。

在这种情况下,Spring 的 ConfigServicePropertySourceLocator 会抛出上述异常并带有误导性的消息:

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]

关于凭证和云配置服务器,Baeldung 教程“Quick Intro to Spring Cloud”说:

We also need to set a username and a password for theBasic-Authentication in our application.properties to avoid anauto-generated password on every application restart.

每次配置客户端向服务器查询配置时都需要这些凭据。我已将凭据添加到“bootstrap.yml”属性文件中:

spring:
cloud:
config:
name: config-test
uri: http://localhost:8081
username: harry
password: potter
fail-fast: true

logging:
level:
com.harry.potter.logging_test: trace

成功了。

关于Spring Boot 云配置客户端未获取云配置,错误消息为 : no suitable HttpMessageConverter found?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66304948/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com