我正在尝试在我的spring-boot应用程序中读取属性。我想读取所有带有前缀“ foo.bar”的属性
我尝试了下面的代码,并且工作正常。
@Configuration
@PropertySources({ @PropertySource(" file:${property.location}/somefile.properties") })
public class SomeClass{
@Bean
@ConfigurationProperties(prefix = "foo.bar")
public Properties getProperties() {
return new Properties();
}
}
但是现在由于某些限制,我不想使用 @PropertySource ,并且我希望我的prefix-properties与上面的结果相同。 现在,我使用PropertyPlaceholderConfigurer而不是@PropertySource来加载属性,如下面的代码所示-
@Bean
public PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer() {
PropertyPlaceholderConfigurer pC = new PropertyPlaceholderConfigurer();
Resource[] resources = new
PathMatchingResourcePatternResolver().getResources(some-path);
pC.setLocations(array);
return pC;
}
请建议是否有一种无需使用@PropertySource即可加载这些前缀属性的方法?