Search in sources :

Example 1 with Bindable

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");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurationProperty(org.springframework.boot.context.properties.source.ConfigurationProperty) BindContext(org.springframework.boot.context.properties.bind.BindContext) Origin(org.springframework.boot.origin.Origin) Binder(org.springframework.boot.context.properties.bind.Binder) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) ArrayList(java.util.ArrayList) Bindable(org.springframework.boot.context.properties.bind.Bindable) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) Test(org.junit.jupiter.api.Test)

Example 2 with Bindable

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);
}
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)2 Bindable (org.springframework.boot.context.properties.bind.Bindable)2 Binder (org.springframework.boot.context.properties.bind.Binder)2 ConfigurationBeanBinder (com.alibaba.spring.context.config.ConfigurationBeanBinder)1 ArrayList (java.util.ArrayList)1 DubboConfigBinder (org.apache.dubbo.config.spring.context.properties.DubboConfigBinder)1 Test (org.junit.jupiter.api.Test)1 BindContext (org.springframework.boot.context.properties.bind.BindContext)1 PropertySourcesPlaceholdersResolver (org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver)1 IgnoreErrorsBindHandler (org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler)1 NoUnboundElementsBindHandler (org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler)1 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)1 ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)1 ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)1 Origin (org.springframework.boot.origin.Origin)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 MapPropertySource (org.springframework.core.env.MapPropertySource)1 PropertySource (org.springframework.core.env.PropertySource)1