spring-boot - 远程连接到PCF云配置服务器服务

标签 spring-boot cloud-foundry spring-cloud-config

我已在 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 应用程序配置中添加以下环境变量

  1. TRUST_CERT - 您的 PCF 基金会网址
  2. VCAP_APPLICATION - VCAP_APPLICATION JSON 紧凑格式*(您可以在 PCF 应用 环境变量 中获取此 jsonapplication_env_json 下)
  3. VCAP_SERVICES - VCAP_SERVICES JSON 紧凑格式*(您可以在 PCF 应用 环境变量 中获取此 jsonsystem_env_json下)

您可以使用this用于格式化 JSON 数据的网站 [选择 Compact JSON 模板]

enter image description here

关于spring-boot - 远程连接到PCF云配置服务器服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54317750/

相关文章:

java - 出现意外错误(类型=内部服务器错误,状态=500)

spring - 我可以拥有多个Spring Cloud Config Server吗?

java - 为什么 bootstrap.properties 被 spring-cloud-starter-config 忽略?

spring-mvc - Pivotal 不起作用 java.io.FileNotFoundException : Could not open ServletContext resource [/WEB-INF/templates

command-line-interface - Pivotal Cloud Foundry 登录问题

java - 关键云类型转换厂的时区变化

git - 从配置服务器获取application.properties时出现Redis连接失败错误

java - Spring Boot @ConfigurationProperties 验证

java - 将 List 中的一个元素的值从 True 更改为 False

java - Spring Batch 多线程数据库读取器