2015-11-17 47 views
2

我已經將我的應用程序從1.2.7(和spring 4.2.2)升級到1.3.0(使用4.2.3)。Spring Boot:升級到1.3.0後的配置順序錯誤

現在我已經看到,我的一些外化配置沒有按預期工作。

例如我有一個屬性值my.property=aaa,它在我的application.yml(包含在我的jar文件包含在類路徑根目錄下)中定義。

現在,如果我啓動命令行我的應用程序,我使用的是外部化的配置文件是這樣的:

java -jar my-app.jar --spring.config.location=file:/mytest.properties 

,其中包括和覆蓋my.property=bbb。在Spring Boot 1.2.7中,結果是bbb - 正如預期的那樣。但在1.3.0中我得到了my.property=aaa!?

如果我呼叫GET:/env端點,我改變了配置的順序。 在1.2.7我*):

... 
"applicationConfig: [classpath:/application-test.yml]": {...}, 
"applicationConfig: [file:/mytest.properties]": {...}, 
"applicationConfig: [classpath:/application.yml]": {...} 
... 

*)這也不是我所期望的,因爲file:/應該是第一個。因此,在我看來,JSON響應中的排序與Spring屬性解析器機制不完全相同。

在1.3.0

取而代之的則是:

... 
"applicationConfig: [classpath:/application.yml]#default": {...}, 
"applicationConfig: [classpath:/application-test.yml]": {...}, 
"applicationConfig: [file:/mytest.properties]": {...} 
... 

我錯過了在更改日誌中的事情?是否還有其他屬性需要設置才能恢復以前的訂單?


編輯:

使一些春天調試測井公司後,我發現它似乎沒有具體的1.3.0問題 - 而且情況下,我的配置工作(即使有1.2.7)只是幸運的巧合......每次重新啓動時的訂購更改。有一次,我得到了我期望的配置。第二次是完全不同的。在代碼或沒有改變我的啓動腳本 - 只是停止/啓動我的應用程序...

我看到這在我的日誌:在1.2.7

(相關的是在此日誌中的最後一行 - 這是正是我期望的那樣):

2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [commandLineArgs] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [servletConfigInitParams] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [servletContextInitParams] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [systemProperties] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [systemEnvironment] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [random] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [classpath:/application-pretest.yml]] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [file:/xxx/service/xxx/properties/xxx_pretest.properties]] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [classpath:/application.yml]] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [commandLineArgs] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [servletConfigInitParams] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [servletContextInitParams] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [systemProperties] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [systemEnvironment] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [random] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [applicationConfig: [classpath:/application-pretest.yml]] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [applicationConfig: [file:/xxx/service/xxx/properties/xxx_pretest.properties]] 
2015-11-18 19:17:39,141 DEBUG core.env.PropertySourcesPropertyResolver - Found key 'xxx.entitlement.endpoint.url' in [applicationConfig: [file:/xxx/service/xxx/properties/xxx_pretest.properties]] with type [String] and value 
'https://xxx:1111/services/EntitlementService' 

在1.3.0(最有趣的是在此日誌中的最後一行 - 意想不到的結果):

2015-11-18 19:34:40,608 DEBUG core.env.MutablePropertySources - Adding [environmentProperties] PropertySource with lowest search precedence 
2015-11-18 19:34:40,608 DEBUG core.env.MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence 
2015-11-18 19:34:40,632 DEBUG core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence 
2015-11-18 19:34:40,632 DEBUG core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence 
2015-11-18 19:34:40,633 DEBUG core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment] 
2015-11-18 19:34:41,044 DEBUG core.env.MutablePropertySources - Adding [commandLineArgs] PropertySource with lowest search precedence 
2015-11-18 19:34:41,044 DEBUG core.env.MutablePropertySources - Adding [servletConfigInitParams] PropertySource with lowest search precedence 
2015-11-18 19:34:41,044 DEBUG core.env.MutablePropertySources - Adding [servletContextInitParams] PropertySource with lowest search precedence 
2015-11-18 19:34:41,045 DEBUG core.env.MutablePropertySources - Adding [systemProperties] PropertySource with lowest search precedence 
2015-11-18 19:34:41,045 DEBUG core.env.MutablePropertySources - Adding [systemEnvironment] PropertySource with lowest search precedence 
2015-11-18 19:34:41,045 DEBUG core.env.MutablePropertySources - Adding [random] PropertySource with lowest search precedence 
2015-11-18 19:34:41,045 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [classpath:/application.yml]#default] PropertySource with lowest search precedence 
2015-11-18 19:34:41,045 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [classpath:/application-pretest.yml]] PropertySource with lowest search precedence 
2015-11-18 19:34:41,045 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [file:/xxx/service/xxx/properties/xxx_pretest.properties]] PropertySource with lowest search precedence 
2015-11-18 19:34:41,045 DEBUG core.env.MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [commandLineArgs] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [servletConfigInitParams] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [servletContextInitParams] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [systemProperties] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [systemEnvironment] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [random] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [classpath:/application.yml]#default] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [classpath:/application-pretest.yml]] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [applicationConfig: [file:/xxx/service/xxx/properties/xxx_pretest.properties]] PropertySource with lowest search precedence 
2015-11-18 19:34:41,046 DEBUG core.env.MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence 
... 
2015-11-18 19:34:42,811 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [environmentProperties] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [commandLineArgs] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [servletConfigInitParams] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [servletContextInitParams] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [systemProperties] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [systemEnvironment] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [random] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [applicationConfig: [classpath:/application.yml]#default] 
2015-11-18 19:34:42,812 DEBUG core.env.PropertySourcesPropertyResolver - Found key 'xxx.entitlement.endpoint.url' in [applicationConfig: [classpath:/application.yml]#default] with type [String] and value 'https://localhost:9448/service 
s/EntitlementService' 

不幸的是,在啓用spring'core.env'日誌之後,整個屬性解析機制對我來說看起來頗爲可疑。我看到大量的DEBUG core.env.MutablePropertySources - Adding [...] PropertySource with lowest search precedence輸出與DEBUG core.env.PropertySourcesPropertyResolver - Searching for key 'xxx.entitlement.endpoint.url' in [...]混合在一起。我預計只有一個區塊Adding [...]之後Searching for key ...塊。但不能混在一起。但我想知道的是爲什麼我的外部配置文件獲得最低優先級而不是最高!?

回答

0

我已經遷移後以下列方式測試這1.3.0.RELEASE:

  • 創建與含有一種配置密鑰捆綁application.properties可運行罐子:

    server.context路徑= /默認

  • /tmp與重寫的配置屬性創建另一個application.properties

    server.context路徑= /超馳

  • 運行jar:java -jar -Dspring.config.location=/tmp/application.properties my-application.jar

申請是現已在http://localhost:8080/override/

本實驗結果與1.2.7.RELEASE一致。

+0

嗯......謝謝你的回答。因此在我看來,我不得不創建一個測試應用程序來重現我的問題(或不)。 –

相關問題