2016-05-06 45 views
3

我有一個彈簧雲問題:執行應用程序時,我沒有使用application.yml中的設置,因爲spring.cloud.config 。讓我在這裏提供更多細節。 我想我的服務可以從遠程ConfigServer獲取設置。我已將ConfigServer創建爲帶有註釋@EnableConfigServer的Spring Boot應用程序。 後,我已經創建了下一個配置文件,客戶端應用程序:執行應用程序時,不會使用application.yml中的設置執行應用程序

application: 
     name: mw 
    cloud: 
     config: 
     enabled: true 
     uri: http://172.17.42.1:8888 
     fail-fast: true 

主類:

@EnableEurekaClient 
    @SpringBootApplication 
    public class MwApplication 

和額外的配置到應用程序:

@Configuration 
    @EnableJpaRepositories(basePackages = {"com.sample.repository"}) 
    @EnableTransactionManagement 
    @EnableScheduling 
    public class AppConfiguration 

還我旁邊的依賴關係:

spring-cloud-starter-eureka 
    spring-cloud-config-client 
    spring-boot-configuration-processor 
    spring-boot-starter-data-jpa 

當我執行我的客戶端應用程序,因爲我得到了這樣的信息:ConfigServicePropertySourceLocator:找不到PropertySource:對GET請求「http://localhost:8888/mw/default

的應用程序試圖從默認的URI(本地主機)的數據I/O錯誤,而不是從我的設置中使用uri。我已經在調試模式下看過app,看到org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration創建了ConfigClientProperties和默認屬性,我的application.yml設置沒有被使用。

我在做什麼錯了? 謝謝。

回答

3

您需要添加以下到您的application.yml文件:

spring: 
    cloud: 
     config: 
      enabled: true 

根據註釋鏈,你還需要添加的屬性bootstrap.yml而不是application.yml。原因是前者在春季啓動週期之前加載後者。這裏是另一個SO後由用戶Michael Isvy解釋爲什麼回答,以下爲複製的後人:What is the diference between putting a property on application.yml or bootstrap.yml in spring boot?

我剛纔問Spring Cloud傢伙,我想我應該分享信息,我這裏有。

bootstrap.yml在application.yml之前加載。

它通常用於以下:

    使用Spring雲配置服務器時
  • ,應指定spring.application.namespring.cloud.config.server.git.uribootstrap.yml
  • 一些encryption/decryption信息

技術上,bootstrap.yml是由父級Spring ApplicationContext加載。該父ApplicationContext在使用application.yml之前加載。

+0

我已經嘗試過了,再次添加,但沒有改變的,我還是有這個問題 – slippery

+1

嘗試移動application.yml配置bootstrap.yml – Andonaeus

+0

現在的作品,謝謝!你能說出爲什麼它不適用於應用程序。陽明海運? 我沒有自己創建application.yml。它是由spring構造函數 – slippery