解决了问题-有两个。
首先,你必须打电话。AfterPropertieSet();在PropertiesFactoryBean上,否则。getObject()返回null。
@Bean(name="commonConfig")
public static PropertiesFactoryBean commonConfig() throws IOException {
PropertiesFactoryBean commonConfig = new PropertiesFactoryBean();
commonConfig.setLocation(new ClassPathResource("META-INF/spring/config.properties"));
try {
commonConfig.afterPropertiesSet();
}
catch (IOException e) {
e.printStackTrace();
throw e;
}
return commonConfig;
}
其次,必须使用以下两个属性调用PropertySourcesPlaceholderConfigurer上的“setPropertiesArray()”:
PropertySourcesPlaceholderConfigurer commonEnvConfig = new PropertySourcesPlaceholderConfigurer();
commonEnvConfig.setPropertiesArray(commonConfig().getObject(), yamlProperties().getObject());