我已在 PCF 中创建了 PCF 配置服务器服务。当我部署充当配置服务客户端的 springboot 应用程序、部署到 PCF 并将其绑定(bind)到配置服务器服务时,它会无缝地提取配置,一切都很好。
我的问题是,在从笔记本电脑本地运行应用程序时,我无法从 springboot 应用程序连接到 PCF 配置服务器。
根据各种文档,我为配置服务器服务创建了服务 key ,并修改了 bootstrap.yml,如下所示。
我收到 401 未经授权的错误。 INFO 22180 --- [ main] c.c.c.ConfigServicePropertySourceLocator :从服务器获取配置:https://config-8660fe8f-2b6b-4171-bd7f-36f3a60ec48a.apps.pcfepg2wi.gm.com 警告 22180 --- [ main] c.c.c.ConfigServicePropertySourceLocator :无法找到 PropertySource:401 未经授权 INFO 22180 --- [ main] com.gm.mms.extfile.Application : tartupProfileInfo - 以下配置文件处于事件状态:dev
spring:
application:
name: external-file-service
profiles:
active: dev
cloud:
config:
uri: https://config-8660fe8f-2b6b-4171-bd7f-
36f3a60ec48a.apps.pcfepg2wi.gm.com
username: <username-here>
password: <password-here>
client_secret: RwKMmAhOzuz8
client_id: p-config-server-ebcd8a29-2615-4924-88bb-b4188d50d2b5
access_token_uri: https://p-spring-cloud-
services.uaa.sys.pcfepg2wi.gm.com/oauth/token
label: develop
security:
basic:
enabled: false
最佳答案
Note: Not sure you can connect any PCF marketplace service from local if Firewall rules are setup to disable the external connectivity.
如果没有连接问题,那么您应该能够使用以下解决方法连接它(对我有用)
在 Spring Boot 应用程序配置中添加以下环境变量
- TRUST_CERT - 您的 PCF 基金会网址
- VCAP_APPLICATION - VCAP_APPLICATION JSON 紧凑格式*(您可以在
PCF
应用环境变量
中获取此json
在application_env_json
下) - VCAP_SERVICES - VCAP_SERVICES JSON 紧凑格式*(您可以在
PCF
应用环境变量
中获取此json
在system_env_json
下)
您可以使用this用于格式化 JSON
数据的网站 [选择 Compact
JSON 模板]
关于spring-boot - 远程连接到PCF云配置服务器服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54317750/