Search in sources :

Example 6 with BindHandler

use of org.springframework.boot.context.properties.bind.BindHandler in project dubbo by alibaba.

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;
}
Also used : IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) UnboundElementsSourceFilter(org.springframework.boot.context.properties.source.UnboundElementsSourceFilter) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler)

Example 7 with BindHandler

use of org.springframework.boot.context.properties.bind.BindHandler 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);
}
Also used : DubboConfigBinder(org.apache.dubbo.config.spring.context.properties.DubboConfigBinder) ConfigurationBeanBinder(com.alibaba.spring.context.config.ConfigurationBeanBinder) Binder(org.springframework.boot.context.properties.bind.Binder) MapPropertySource(org.springframework.core.env.MapPropertySource) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) Bindable(org.springframework.boot.context.properties.bind.Bindable) PropertySourcesPlaceholdersResolver(org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) PropertySource(org.springframework.core.env.PropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource)

Example 8 with BindHandler

use of org.springframework.boot.context.properties.bind.BindHandler in project spring-boot by spring-projects.

the class ConfigDataEnvironmentContributors method getBinder.

private Binder getBinder(ConfigDataActivationContext activationContext, Predicate<ConfigDataEnvironmentContributor> filter, Set<BinderOption> options) {
    boolean failOnInactiveSource = options.contains(BinderOption.FAIL_ON_BIND_TO_INACTIVE_SOURCE);
    Iterable<ConfigurationPropertySource> sources = () -> getBinderSources(filter.and((contributor) -> failOnInactiveSource || contributor.isActive(activationContext)));
    PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(this.root, activationContext, null, failOnInactiveSource);
    BindHandler bindHandler = !failOnInactiveSource ? null : new InactiveSourceChecker(activationContext);
    return new Binder(sources, placeholdersResolver, null, null, bindHandler);
}
Also used : Kind(org.springframework.boot.context.config.ConfigDataEnvironmentContributor.Kind) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) BindContext(org.springframework.boot.context.properties.bind.BindContext) Bindable(org.springframework.boot.context.properties.bind.Bindable) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) ConfigurableBootstrapContext(org.springframework.boot.ConfigurableBootstrapContext) ObjectUtils(org.springframework.util.ObjectUtils) Set(java.util.Set) Collectors(java.util.stream.Collectors) ImportPhase(org.springframework.boot.context.config.ConfigDataEnvironmentContributor.ImportPhase) ArrayList(java.util.ArrayList) LogMessage(org.springframework.core.log.LogMessage) List(java.util.List) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) Map(java.util.Map) Log(org.apache.commons.logging.Log) Binder(org.springframework.boot.context.properties.bind.Binder) DeferredLogFactory(org.springframework.boot.logging.DeferredLogFactory) Collections(java.util.Collections) EnumSet(java.util.EnumSet) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) Binder(org.springframework.boot.context.properties.bind.Binder) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) BindHandler(org.springframework.boot.context.properties.bind.BindHandler)

Example 9 with BindHandler

use of org.springframework.boot.context.properties.bind.BindHandler in project spring-boot by spring-projects.

the class ConfigurationPropertiesBinder method bindOrCreate.

Object bindOrCreate(ConfigurationPropertiesBean propertiesBean) {
    Bindable<?> target = propertiesBean.asBindTarget();
    ConfigurationProperties annotation = propertiesBean.getAnnotation();
    BindHandler bindHandler = getBindHandler(target, annotation);
    return getBinder().bindOrCreate(annotation.prefix(), target, bindHandler);
}
Also used : IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BoundPropertiesTrackingBindHandler(org.springframework.boot.context.properties.bind.BoundPropertiesTrackingBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) IgnoreTopLevelConverterNotFoundBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreTopLevelConverterNotFoundBindHandler) ValidationBindHandler(org.springframework.boot.context.properties.bind.validation.ValidationBindHandler) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) AbstractBindHandler(org.springframework.boot.context.properties.bind.AbstractBindHandler)

Example 10 with BindHandler

use of org.springframework.boot.context.properties.bind.BindHandler in project incubator-dubbo-spring-boot-project by apache.

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);
}
Also used : DubboConfigBinder(org.apache.dubbo.config.spring.context.properties.DubboConfigBinder) ConfigurationBeanBinder(com.alibaba.spring.context.config.ConfigurationBeanBinder) Binder(org.springframework.boot.context.properties.bind.Binder) MapPropertySource(org.springframework.core.env.MapPropertySource) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) Bindable(org.springframework.boot.context.properties.bind.Bindable) PropertySourcesPlaceholdersResolver(org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) PropertySource(org.springframework.core.env.PropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource)

Aggregations

BindHandler (org.springframework.boot.context.properties.bind.BindHandler)10 IgnoreErrorsBindHandler (org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler)7 NoUnboundElementsBindHandler (org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler)7 Binder (org.springframework.boot.context.properties.bind.Binder)5 Bindable (org.springframework.boot.context.properties.bind.Bindable)4 ArrayList (java.util.ArrayList)3 AbstractBindHandler (org.springframework.boot.context.properties.bind.AbstractBindHandler)3 BoundPropertiesTrackingBindHandler (org.springframework.boot.context.properties.bind.BoundPropertiesTrackingBindHandler)3 IgnoreTopLevelConverterNotFoundBindHandler (org.springframework.boot.context.properties.bind.handler.IgnoreTopLevelConverterNotFoundBindHandler)3 ValidationBindHandler (org.springframework.boot.context.properties.bind.validation.ValidationBindHandler)3 ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)3 UnboundElementsSourceFilter (org.springframework.boot.context.properties.source.UnboundElementsSourceFilter)3 PropertySource (org.springframework.core.env.PropertySource)3 ConfigurationBeanBinder (com.alibaba.spring.context.config.ConfigurationBeanBinder)2 DubboConfigBinder (org.apache.dubbo.config.spring.context.properties.DubboConfigBinder)2 ConfigurableBootstrapContext (org.springframework.boot.ConfigurableBootstrapContext)2 BindContext (org.springframework.boot.context.properties.bind.BindContext)2 PropertySourcesPlaceholdersResolver (org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver)2 ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)2 MapPropertySource (org.springframework.core.env.MapPropertySource)2