我面臨着一些挑戰,基於一些值可用在其他屬性文件中創建PropertySourcesPlaceholderConfigurer。 我有一個屬性文件custom- {environment} .property,它包含一個值,用於設置PropertySourcesPlaceholderConfigurer的位置。使用屬性創建自定義PropertySourcesPlaceholderConfigurer動態加載
我CustomConfiguration看起來像:
@Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
propertySourcesPlaceholderConfigurer.setLocation(customLocation);
//Custom url location based on a String available in the properties file. This is the problem area
return propertySourcesPlaceholderConfigurer;
}
我要填充這個customLocation
從屬性文件。嘗試自動裝配環境,但它失敗,因爲當調用placeholderConfigurer()
時環境爲空。嘗試使用@PropertySource("custom-${environment}.property")
,然後@Value("**customLocation**")
,但這也不起作用。
請讓我知道如何可以做到這一點。提前致謝。
我想說,添加一個'ApplicationContextInitializer'來加載'custom- {environment} .properties',然後加載額外的配置文件,是easiests,你可以再補充一個'PropertySource'的方式。 – 2014-09-23 05:54:02