2016-02-12 49 views
4

我試圖完成團隊設置websphere配置文件活動時雲配置文件也被激活。Spring配置文件包含yaml文件的問題

YAML文件

--- 
    spring: 
     application: 
     name: kicapp 
     output: 
     ansi: 
      enabled: ALWAYS 
     profiles: 
     active: local 
    #server: 
     #context-path:/
     #port: 8080 
    #logging: 
     #level: 
     #org.springframework.security: DEBUG 
    --- 
    spring: 
     profiles: local 
    --- 
    spring: 
     profiles: unittest 
    --- 
    spring: 
     profiles: cloud 
     test: loaded 
    --- 
    spring: 
     profiles: websphere 
     include: cloud 

當我設置--spring.profiles.active=websphere我收到以下錯誤

引起:映射值在這裏不容許 '讀取器',第28行, 柱12: 包括:雲

+0

試圖刪除'include'前面的''? – Marged

+0

@大小,以便'include'不嵌套在'profiles'中? – ndrone

+0

看看這個嗎? http://stackoverflow.com/questions/25985752/including-profiles-with-spring-profiles-include-seems-to-override-instead-of-inc。你使用哪個版本的Spring? – Marged

回答

3

這似乎是的限制解析器和Spring Boot使用它的方式。由於yaml允許使用---分隔符在單個文件中指定多個不同的文檔,所以Spring分離出單獨文檔的方式是使用spring.profiles鍵,因此該關鍵字可能是一個簡單的結構,而且不是一個複雜的結構。

一個很好的解決方法其實是這對分割成多個文件是這樣的:在地方關鍵spring.profiles.include預期將工作

application.yaml共同內容, application-<profile>與輪廓特定的擴展,採用這種結構。