use of org.springframework.boot.context.properties.bind.Bindable in project spring-boot by spring-projects.
the class ConfigDataEnvironmentPostProcessorIntegrationTests method runWhenImportingIncludesParentOrigin.
@Test
void runWhenImportingIncludesParentOrigin() {
ConfigurableApplicationContext context = this.application.run("--spring.config.location=classpath:application-import-with-placeholder.properties");
Binder binder = Binder.get(context.getEnvironment());
List<ConfigurationProperty> properties = new ArrayList<>();
BindHandler bindHandler = new BindHandler() {
@Override
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {
properties.add(context.getConfigurationProperty());
return result;
}
};
binder.bind("my.value", Bindable.of(String.class), bindHandler);
assertThat(properties).hasSize(1);
Origin origin = properties.get(0).getOrigin();
assertThat(origin.toString()).contains("application-import-with-placeholder-imported");
assertThat(origin.getParent().toString()).contains("application-import-with-placeholder");
}
use of org.springframework.boot.context.properties.bind.Bindable in project dubbo by alibaba.
the class BinderDubboConfigBinder method bind.
@Override
public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, boolean ignoreInvalidFields, Object configurationBean) {
Iterable<PropertySource<?>> propertySources = asList(new MapPropertySource("internal", configurationProperties));
// Converts ConfigurationPropertySources
Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources);
// Wrap Bindable from DubboConfig instance
Bindable bindable = Bindable.ofInstance(configurationBean);
Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources));
// Get BindHandler
BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields);
// Bind
binder.bind("", bindable, bindHandler);
}
Aggregations