在spring启动应用程序启动期间,是否可以从web服务加载属性?
我正在构建一个可部署到bluemix(cloud foundry)的新spring boot应用程序,该应用程序需要执行以下操作:在spring启动应用程序启动期间,是否可以从web服务加载属性?,spring,spring-boot,properties,external,Spring,Spring Boot,Properties,External,我正在构建一个可部署到bluemix(cloud foundry)的新spring boot应用程序,该应用程序需要执行以下操作: 使用SpringCloudFoundry连接器发现用户提供的“属性服务”:从VCAP_应用程序环境变量读取服务URL和凭据。 此步骤已完成 通过HTTP调用连接到properties服务,接收JSON响应,解析各个属性值并将它们作为应用程序属性公开(在环境对象中?) 在spring boot应用程序中,正确的解决方案是什么 在较旧的非启动Spring应用程序中,属性
public class CustomPopertiesFactory
extends PropertySourcesPlaceholderConfigurer
implements EnvironmentAware {
private Properties properties;
getServiceCredentials() {
// parse VCAP_APPLICATION json
final String localVcapServices = System.getProperty("VCAP_SERVICES");
// extract url, username, pwd to connect to the service
}
connectToService () {
// via HTTP request using RestTemplate
// parse JSON response and add properties to this.properties
... this.properties.put("prop1", valueFromJson);
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
getServiceCredentials();
connectToService();
// load values from properties service into app properties
setProperties(properties);
// continue with lifecycle and load properties from other sources
super.postProcessBeanFactory(beanFactory);
}
}
在IMO中维护和切换云和本地spring配置文件是一件痛苦的事情,我想知道spring boot是否有更好的方法来处理外部属性。我最终用
并使用在我的spring启动应用程序中,使用spring云配置服务器的属性