我很難將Spring Boot應用程序配置爲通過Spring-Cloud連接到提供的PWS(Pivotal Web Services)Config-Server - 連接器。使用Spring-Cloud-Connectors配置Spring Boot以使用PWS Config-Server
在manifest.yml的配置服務器被綁定到應用程序,它被正確地由相應的,VCAP_SERVICES條目反射:
applications:
- name: edge-service-webapp-myapp
services:
- infrastructure-config-server
memory: 512M
env:
TRUST_CERTS: api.run.pivotal.io
SPRING_PROFILES_DEFAULT: cloud
instances: 1
host: edge-service-webapp-myapp
domain: cfapps.io
buildpack: java_buildpack
{
"VCAP_SERVICES": {
"p-config-server": [
{
"credentials": {
"access_token_uri": "https://p-spring-cloud-services.uaa.run.pivotal.io/oauth/token",
"client_id": "p-config-server-84d66ea6-ebc6-xxx",
"client_secret": "***",
"uri": "https://config-b4320676-xxx.cfapps.io"
}, ...
}
該應用程序是建立與彈簧引導起動父1.5。 2.RELEASE,spring-cloud-dependencies Camden.SR5和spring-cloud-services-dependencies 1.4.1.RELEASE。此外,我使用spring-cloud-starter-config和spring-boot-starter-cloud-connectors作爲顯式依賴項。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-dependencies</artifactId>
<version>1.4.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
....
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
...
當我蜷縮在配置服務器,我可以看到可用的應用程序名稱(MY-APP)和主動「雲」配置文件中的應用程序版本。
spring:
application:
name: my-app
cloud:
config:
enabled: true
curl -H "Authorization: Bearer XXX" https://config-b4320676-xxx.cfapps.io/tradefoundry/cloud
{"name":"my-app","profiles":["cloud"],"label":"master","version":"389e4f909ff1303332167b2159b4d75201109d69","state":null,"propertySources":[{"name":"https://gitlab.com/myapp/configuration.git/myapp-cloud.properties","source":{"spring.thymeleaf.cache":"true","message":"Hello Cloud!"}},{"name":"https://gitlab.com/myapp/configuration.git/myapp.properties","source":{"server.compression.enabled":"true","spring.thymeleaf.cache":"true","application.version":"0.0.1"}},{"name":"https://gitlab.com/myapp/configuration.git/application.properties","source":{"server.compression.enabled":"true","spring.thymeleaf.cache":"true","application.cache.busting.enabled":"false","application.version":"0.0.1-20170202195700","server.compression.mime-types":"application/json,application/xml,text/html,text/xml,text/plain,text/css,application/javascript"}}]}
但仍是應用程序失敗在啓動時,抱怨缺少財產application.version。
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myWebappApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'application.version' in value "${application.version}"
我在這裏錯過了什麼?我認爲雲連接器都是通過自動配置即插即用的!
歡迎任何幫助!
你救了我的一天! ...現在我覺得有點愚蠢,因爲跳過文檔的那一部分...我草率地... – achingfingers
文檔是偉大的 - 一旦你發現它們存在和他們住在哪裏。這些可能不是最容易找到的文檔。我很高興聽到解決您的問題。 –