如何在cf vcaps env中更新postgres uri值 [英] How to update postgres uri value in cf vcaps env

查看:111
本文介绍了如何在cf vcaps env中更新postgres uri值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CF(Cloud Foundry)
中的春季应用程序中绑定了Postgres服务。可用的VCAPS env如下:

I have a bound Postgres service to my spring application in CF (Cloud foundry) The VCAPS env available are as following:

"postgresql": [
   {
    "binding_name": null,
    "credentials": {
     "dbname": "JDusZ6EpE1ixbTKS",
     "end_points": [
      {
       "host": "10.11.241.2",
       "network_id": "SF",
       "port": "46371"
      }
     ],
     "hostname": "10.11.241.2",
     "password": "SuVzOf2m5L5oNYSG",
     "port": "46371",
     "ports": {
      "5432/tcp": "46371"
     },
     "uri": "postgres://eyv6avf27X9Z55Gx:SuVzOf2m5L5oNYSG@10.11.241.2:46371/JDusZ6EpE1ixbTKS",
     "username": "eyv6avf27X9Z55Gx"
    },
    "instance_name": "mypostgres",
    "label": "postgresql",
    "name": "mypostgres",
    "plan": "v9.6-dev",
    "provider": null,
    "syslog_drain_url": null,
    "tags": [
     "postgresql",
     "relational"
    ],
    "volume_mounts": []
   }
  ],

我需要调整uri的值以包含当前架构,我想应该是:

I need to modefy the value of the uri to include also the current schema, I guess it needs to be as:

 "uri": "postgres://eyv6avf27X9Z55Gx:SuVzOf2m5L5oNYSG@10.11.241.2:46371/JDusZ6EpE1ixbTKS?currentSchema=mycurrentschema"

这可能吗?如果不是,最好的做法是为spring应用分配当前模式?

Is this something possible to do? and If not what is the best practice to assign current schema for a spring app?

预先感谢

推荐答案

您有一些选择。


  1. 您可以与服务提供商联系,您从中获取服务的服务代理的操作员。服务代理是设置凭据的代理,因此您可以默认要求它们包括模式。

  1. You can talk to your service provider, the operator of the service broker from which you are obtaining your service. The service broker is the one that sets the credentials, so you could ask them to include the schema by default.

您可以使用<$创建服务密钥c $ c> cf create-service-key 。服务密钥就像服务绑定一样,但是可以自由浮动,因此不会附加到您的应用中。只要服务密钥存在,它就存在。然后,您可以使用 cf cups 创建用户提供的服务,并手动设置应用所需的任何凭据或uri。这种方法的缺点是您必须做更多的工作来管理服务信息。

You can create a service key with cf create-service-key. The service key is like a service binding, but free floating so it's not attached to your app. It just exists as long as the service key exists. You can then create a user provided service, with cf cups and manually set whatever credentials or uri you require for your app. The downside of this approach is that you have to do a little more work to manage the service information.

您可以将当前uri读入应用程序并进行修改在创建您的数据源之前。如果您使用的是Spring Cloud Connectors,这并不是特别容易,因为它可以为您创建DataSource。我不建议使用SCC。

You can read the current uri into your application and modify it before creating your DataSource. This is not particularly easy if you are using Spring Cloud Connectors because it handles creating the DataSource for you. I would not recommend using SCC.

相反,您可以使用Spring Boot CloudFoundryVcapEnvironmentPostProcessor 和财产占位符。

Instead you can do this with the Spring Boot CloudFoundryVcapEnvironmentPostProcessor and property place holders. See the referenced Javadoc for how that works.

另一种选择是使用 java-cvenv 。这为您提供了一种获取凭据信息(如URL)的简便方法,并使用它来创建自己的数据源,该数据源可让您在必要时对诸如URL之类的内容进行一些修改。

The other option is to use java-cvenv. That provides you with an easy way to obtain credentials information, like the URL and use that to create your own DataSource, which allows you to make slight modifications to things like the URL, if necessary.

希望有帮助!

这篇关于如何在cf vcaps env中更新postgres uri值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆