use of org.springframework.boot.context.properties.bind.BindHandler in project incubator-dubbo-spring-boot-project by apache.
the class BinderDubboConfigBinder method getBindHandler.
private BindHandler getBindHandler(boolean ignoreUnknownFields, boolean ignoreInvalidFields) {
BindHandler handler = BindHandler.DEFAULT;
if (ignoreInvalidFields) {
handler = new IgnoreErrorsBindHandler(handler);
}
if (!ignoreUnknownFields) {
UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
handler = new NoUnboundElementsBindHandler(handler, filter);
}
return handler;
}
use of org.springframework.boot.context.properties.bind.BindHandler in project apollo by ctripcorp.
the class ApolloConfigDataLoader method load.
@Override
public ConfigData load(ConfigDataLoaderContext context, ApolloConfigDataResource resource) throws IOException, ConfigDataResourceNotFoundException {
ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext();
Binder binder = bootstrapContext.get(Binder.class);
BindHandler bindHandler = this.getBindHandler(context);
bootstrapContext.registerIfAbsent(ApolloConfigDataLoaderInitializer.class, InstanceSupplier.from(() -> new ApolloConfigDataLoaderInitializer(this.log, binder, bindHandler, bootstrapContext)));
ApolloConfigDataLoaderInitializer apolloConfigDataLoaderInitializer = bootstrapContext.get(ApolloConfigDataLoaderInitializer.class);
// init apollo client
List<PropertySource<?>> initialPropertySourceList = apolloConfigDataLoaderInitializer.initApolloClient();
// load config
bootstrapContext.registerIfAbsent(ConfigPropertySourceFactory.class, InstanceSupplier.from(() -> SpringInjector.getInstance(ConfigPropertySourceFactory.class)));
ConfigPropertySourceFactory configPropertySourceFactory = bootstrapContext.get(ConfigPropertySourceFactory.class);
String namespace = resource.getNamespace();
Config config = ConfigService.getConfig(namespace);
ConfigPropertySource configPropertySource = configPropertySourceFactory.getConfigPropertySource(namespace, config);
List<PropertySource<?>> propertySourceList = new ArrayList<>();
propertySourceList.add(configPropertySource);
propertySourceList.addAll(initialPropertySourceList);
log.debug(Slf4jLogMessageFormatter.format("apollo client loaded namespace [{}]", namespace));
return new ConfigData(propertySourceList);
}
use of org.springframework.boot.context.properties.bind.BindHandler 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.BindHandler in project spring-boot by spring-projects.
the class ConfigurationPropertiesBinder method bind.
BindResult<?> bind(ConfigurationPropertiesBean propertiesBean) {
Bindable<?> target = propertiesBean.asBindTarget();
ConfigurationProperties annotation = propertiesBean.getAnnotation();
BindHandler bindHandler = getBindHandler(target, annotation);
return getBinder().bind(annotation.prefix(), target, bindHandler);
}
use of org.springframework.boot.context.properties.bind.BindHandler in project spring-boot by spring-projects.
the class ConfigurationPropertiesBinder method getBindHandler.
private <T> BindHandler getBindHandler(Bindable<T> target, ConfigurationProperties annotation) {
List<Validator> validators = getValidators(target);
BindHandler handler = getHandler();
handler = new ConfigurationPropertiesBindHandler(handler);
if (annotation.ignoreInvalidFields()) {
handler = new IgnoreErrorsBindHandler(handler);
}
if (!annotation.ignoreUnknownFields()) {
UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
handler = new NoUnboundElementsBindHandler(handler, filter);
}
if (!validators.isEmpty()) {
handler = new ValidationBindHandler(handler, validators.toArray(new Validator[0]));
}
for (ConfigurationPropertiesBindHandlerAdvisor advisor : getBindHandlerAdvisors()) {
handler = advisor.apply(handler);
}
return handler;
}
Aggregations