在application.properties中引用VCAP变量

时间:2017-07-27 14:20:29

标签: cloudfoundry

我的VCAP如下所示:

"VCAP_SERVICES": {
        "rabbitmq": [
                    {
                   "credentials": {
                   "hostname": "10.11.241.52",
                   "ports": {
                             "15672/tcp": "52764",
                             "5672/tcp": "42204"

我的问题是如何在application.properties中引用值“52764”?请注意,我们正在构建spring boot应用程序。

谢谢你,最诚挚的问候, 衙署

1 个答案:

答案 0 :(得分:2)

在该示例中,您应该能够在application.properties中使用这些属性:

spring.rabbitmq.host: ${vcap.services.rabbitmq.credentials.hostname} spring.rabbitmq.port: ${vcap.services.rabbitmq.credentials.ports.15672/tcp}

${vcap.services...}占位符由Spring Boot环境后处理器启用。 JavaDoc for that class中提供了一些详细信息。

可以在Spring blog post中找到更多详细信息,以及在Spring应用中访问VCAP_SERVICES中的信息的一些替代方法。

相关问题