2017-06-22 38 views
-1

我正在用spring-boot寫一個微服務。 db是mongodb。該服務在我的本地環境中完美運行。但是,在將其部署到雲代工廠之後,它不起作用。原因是連接mongodb超時。彈簧引導應用程序如何確定它是否在雲代工廠上運行?

我認爲根本原因是應用程序不知道它在雲上運行。因爲它仍然連接127.0.0.1:27017,但不是重定向的端口。

它怎麼知道它在雲上運行?謝謝!

編輯:

有綁定到服務MongoDB實例。而當我檢查了環境信息,我得到了以下信息:

{ 
    "VCAP_SERVICES": { 
     "mongodb": [ 
      { 
       "credentials": { 
        "hostname": "10.11.241.1", 
        "ports": { 
         "27017/tcp": "43417", 
         "28017/tcp": "43135" 
        }, 
        "port": "43417", 
        "username": "xxxxxxxxxx", 
        "password": "xxxxxxxxxx", 
        "dbname": "gwkp7glhw9tq9cwp", 
        "uri": "xxxxxxxxxx" 
       }, 
       "syslog_drain_url": null, 
       "volume_mounts": [], 
       "label": "mongodb", 
       "provider": null, 
       "plan": "v3.0-container", 
       "name": "mongodb-business-configuration", 
       "tags": [ 
        "mongodb", 
        "document" 
       ] 
      } 
     ] 
    } 
} 
{ 
    "VCAP_APPLICATION": { 
     "cf_api": "xxxxxxxxxx", 
     "limits": { 
      "fds": 16384, 
      "mem": 1024, 
      "disk": 1024 
     }, 
     "application_name": "mock-service", 
     "application_uris": [ 
      "xxxxxxxxxx" 
     ], 
     "name": "mock-service", 
     "space_name": "xxxxxxxxxx", 
     "space_id": "xxxxxxxxxx", 
     "uris": [ 
      "xxxxxxxxxx" 
     ], 
     "users": null, 
     "application_id": "xxxxxxxxxx", 
     "version": "c7569d23-f3ee-49d0-9875-8e595ee76522", 
     "application_version": "c7569d23-f3ee-49d0-9875-8e595ee76522" 
    } 
} 

從我的理解,我覺得我的春天啓動的服務應該嘗試連接端口43417,但不是27017,對不對?謝謝!

+0

因爲你實際上並沒有一個['mongod'](https://docs.mongodb.com/manual/reference/program/mongod/ )服務與應用程序相同的實例?如何指向一個遠程MongoDB來代替。 https://www.google.com/search?q=mongodb+hosting+providers –

+0

這裏有一個「生態系統」中的官方文檔部分:[VMware Cloud Foundry](https://docs.mongodb.com/生態系統/平臺/ vmware-cloud-foundry /) –

+0

謝謝你們,實際上有一個mongodb實例綁定到服務。我也編輯這個問題來宣佈它。 –

回答

0

最後我發現原因是我沒有指定配置文件。在我manifest.yml添加以下代碼後,它的工作原理:

env: 
    SPRING_PROFILES_ACTIVE: cloud 
+0

這聽起來不對,你不應該那樣做。你使用的是什麼樣的cloudfoundry發行版? –

相關問題