我有server.yml
文件,其中包含僅限於Spring Framework屬性,如端口號,上下文根路徑,應用程序名稱。將文件添加到Spring Boot的類路徑
而且,我有一個applicationContext.xml
有以下幾點:
<util:properties id="springProperties" location="classpath*:my.properties">
<context:property-placeholder location="classpath*:my.properties"
local-override="true" properties-ref="springProperties" />
my.properties
文件駐留在src/main/resources
目錄項目。
那麼,我可以從我的Java類,如訪問屬性:
@Autowired
@Qualifier("springProperties")
private Properties props;
public String getProperty(String key){
return props.getProperty(key);
}
or like `${my.prop}`
當我建立戰爭和運行春季啓動(java -jar server.war
),內部my.properties
議決,一切都按預期工作。
但是,我想覆蓋該文件與外部my.properties
。 我讀https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
我試圖運行是這樣的:
java -jar server.jar --spring.config.location=classpath:/my.properties
或
java -jar server.jar --spring.config.location=my.properties
但我可以通過這個覆蓋的屬性只有從我server.yml
。意思是說,我可以覆蓋端口號或應用程序名稱。但內部my.properties
從不受影響。
我做錯了什麼?我明白,外部my.property
只是應該在類路徑中,然後它覆蓋內部my.property
。但它從未發生過。
您是否嘗試過在沒有此配置的'springProperties'限定符的情況下執行此操作?您在外部加載的'my.properties'副本可能不會影響該上下文。 – dillius