我使用S3作为Spring Config服务器的后端。我在我的bucket中上传了3个文件。
- application-local.properties
- 应用程序专用属性
- application-qa.properties
然后,我将尝试达到文档中提到的REST API端点。
网址:http://localhost:4000/application/qa
9秒后,我得到了200的回复,下面是身体。
"name": "application",
"profiles": [
"qa"
],
"label": null,
"version": null,
"state": null,
"propertySources": []
}
从技术上讲,我应该在propertySources中获取数据,但我什么都没得到。
配置服务器应用程序属性
server.port=4000
debug=true
# AWS credentials
cloud.aws.credentials.accessKey=*************
cloud.aws.credentials.secretKey=******************************
cloud.aws.region=ap-south-1
spring.profiles.active=awss3
spring.cloud.config.server.awss3.region=ap-south-1
spring.cloud.config.server.awss3.bucket=mybucket
# Spring Admin server port
spring.boot.admin.client.url=http://localhost:2000/
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
spring.cloud.config.server.bootstrap=true
配置服务器日志
2021-10-21 22:54:21.820 INFO 33105 --- [ restartedMain] c.h.a.c.ConfigserverApplication : Started ConfigserverApplication in 0.346 seconds (JVM running for 2822.873)
2021-10-21 22:54:21.821 DEBUG 33105 --- [ restartedMain] o.s.b.a.ApplicationAvailabilityBean : Application availability state LivenessState changed to CORRECT
2021-10-21 22:54:21.823 INFO 33105 --- [ restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
2021-10-21 22:54:21.823 DEBUG 33105 --- [ restartedMain] o.s.b.a.ApplicationAvailabilityBean : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
2021-10-21 22:54:23.429 INFO 33105 --- [nio-4000-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-10-21 22:54:23.429 INFO 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-10-21 22:54:23.429 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Detected StandardServletMultipartResolver
2021-10-21 22:54:23.429 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Detected AcceptHeaderLocaleResolver
2021-10-21 22:54:23.429 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Detected FixedThemeResolver
2021-10-21 22:54:23.430 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@1122dbe3
2021-10-21 22:54:23.430 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.support.SessionFlashMapManager@1fe527b7
2021-10-21 22:54:23.430 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2021-10-21 22:54:23.430 INFO 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2021-10-21 22:54:23.430 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : GET "/application/qa", parameters={}
2021-10-21 22:54:23.431 DEBUG 33105 --- [nio-4000-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.cloud.config.server.environment.EnvironmentController#defaultLabel(String, String)
2021-10-21 22:54:32.853 DEBUG 33105 --- [nio-4000-exec-2] m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json', given [*/*] and supported [application/json]
2021-10-21 22:54:32.855 DEBUG 33105 --- [nio-4000-exec-2] m.m.a.RequestResponseBodyMethodProcessor : Writing [Environment [name=application, profiles=[qa], label=null, propertySources=[], version=null, state=nu (truncated)...]
2021-10-21 22:54:32.856 DEBUG 33105 --- [nio-4000-exec-2] o.s.web.servlet.DispatcherServlet : Completed 200 OK
我不知道如何解决这个问题。
有几件事可能会有所帮助。如果您使用的是Spring Boot>=2.4,属性spring.cloud.config.server.bootstrap=true
需要作为命令行参数或通过此处的maven启动器提供。该属性必须在";引导程序";读取CCD_ 3之前的相位。
它可能与以下内容有关:
- IAM访问所选存储桶
- 凭据-在使用配置服务器时,我只使用了针对AWS S3的提供程序链进行身份验证。从源代码来看,提供程序链似乎是创建S3客户端的唯一方法。遗憾的是,您不能配置自己的
AmazonS3
bean
您得到的响应表明应用程序可以与S3对话,但无法找到属性。如果Spring Config Server无法与S3通信,则在命中/actuator/health
时,它将报告DOWN
。你的应用程序在执行器中显示健康吗?