org.springframework.boot.context.properties.bind

Class Binder

  • java.lang.Object
    • org.springframework.boot.context.properties.bind.Binder


  • public class Binder
    extends java.lang.Object
    A container object which Binds objects from one or more ConfigurationPropertySources.
    Since:
    2.0.0
    • Constructor Detail

      • Binder

        public Binder(ConfigurationPropertySource... sources)
        Create a new Binder instance for the specified sources. A DefaultFormattingConversionService will be used for all conversion.
        Parameters:
        sources - the sources used for binding
      • Binder

        public Binder(java.lang.Iterable<ConfigurationPropertySource> sources)
        Create a new Binder instance for the specified sources. A DefaultFormattingConversionService will be used for all conversion.
        Parameters:
        sources - the sources used for binding
      • Binder

        public Binder(java.lang.Iterable<ConfigurationPropertySource> sources,
                      PlaceholdersResolver placeholdersResolver)
        Create a new Binder instance for the specified sources.
        Parameters:
        sources - the sources used for binding
        placeholdersResolver - strategy to resolve any property placeholders
      • Binder

        public Binder(java.lang.Iterable<ConfigurationPropertySource> sources,
                      PlaceholdersResolver placeholdersResolver,
                      org.springframework.core.convert.ConversionService conversionService)
        Create a new Binder instance for the specified sources.
        Parameters:
        sources - the sources used for binding
        placeholdersResolver - strategy to resolve any property placeholders
        conversionService - the conversion service to convert values (or null to use ApplicationConversionService)
      • Binder

        public Binder(java.lang.Iterable<ConfigurationPropertySource> sources,
                      PlaceholdersResolver placeholdersResolver,
                      org.springframework.core.convert.ConversionService conversionService,
                      java.util.function.Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer)
        Create a new Binder instance for the specified sources.
        Parameters:
        sources - the sources used for binding
        placeholdersResolver - strategy to resolve any property placeholders
        conversionService - the conversion service to convert values (or null to use ApplicationConversionService)
        propertyEditorInitializer - initializer used to configure the property editors that can convert values (or null if no initialization is required). Often used to call ConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry).
      • Binder

        public Binder(java.lang.Iterable<ConfigurationPropertySource> sources,
                      PlaceholdersResolver placeholdersResolver,
                      org.springframework.core.convert.ConversionService conversionService,
                      java.util.function.Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer,
                      BindHandler defaultBindHandler)
        Create a new Binder instance for the specified sources.
        Parameters:
        sources - the sources used for binding
        placeholdersResolver - strategy to resolve any property placeholders
        conversionService - the conversion service to convert values (or null to use ApplicationConversionService)
        propertyEditorInitializer - initializer used to configure the property editors that can convert values (or null if no initialization is required). Often used to call ConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry).
        defaultBindHandler - the default bind handler to use if none is specified when binding
        Since:
        2.2.0
      • Binder

        public Binder(java.lang.Iterable<ConfigurationPropertySource> sources,
                      PlaceholdersResolver placeholdersResolver,
                      org.springframework.core.convert.ConversionService conversionService,
                      java.util.function.Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer,
                      BindHandler defaultBindHandler,
                      BindConstructorProvider constructorProvider)
        Create a new Binder instance for the specified sources.
        Parameters:
        sources - the sources used for binding
        placeholdersResolver - strategy to resolve any property placeholders
        conversionService - the conversion service to convert values (or null to use ApplicationConversionService)
        propertyEditorInitializer - initializer used to configure the property editors that can convert values (or null if no initialization is required). Often used to call ConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry).
        defaultBindHandler - the default bind handler to use if none is specified when binding
        constructorProvider - the constructor provider which provides the bind constructor to use when binding
        Since:
        2.2.1
      • Binder

        public Binder(java.lang.Iterable<ConfigurationPropertySource> sources,
                      PlaceholdersResolver placeholdersResolver,
                      java.util.List<org.springframework.core.convert.ConversionService> conversionServices,
                      java.util.function.Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer,
                      BindHandler defaultBindHandler,
                      BindConstructorProvider constructorProvider)
        Create a new Binder instance for the specified sources.
        Parameters:
        sources - the sources used for binding
        placeholdersResolver - strategy to resolve any property placeholders
        conversionServices - the conversion services to convert values (or null to use ApplicationConversionService)
        propertyEditorInitializer - initializer used to configure the property editors that can convert values (or null if no initialization is required). Often used to call ConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry).
        defaultBindHandler - the default bind handler to use if none is specified when binding
        constructorProvider - the constructor provider which provides the bind constructor to use when binding
        Since:
        2.5.0
    • Method Detail

      • bind

        public <T> BindResult<T> bind(java.lang.String name,
                                      Bindable<T> target,
                                      BindHandler handler)
        Bind the specified target Bindable using this binder's property sources.
        Type Parameters:
        T - the bound type
        Parameters:
        name - the configuration property name to bind
        target - the target bindable
        handler - the bind handler (may be null)
        Returns:
        the binding result (never null)
      • bind

        public <T> BindResult<T> bind(ConfigurationPropertyName name,
                                      Bindable<T> target,
                                      BindHandler handler)
        Bind the specified target Bindable using this binder's property sources.
        Type Parameters:
        T - the bound type
        Parameters:
        name - the configuration property name to bind
        target - the target bindable
        handler - the bind handler (may be null)
        Returns:
        the binding result (never null)
      • bindOrCreate

        public <T> T bindOrCreate(java.lang.String name,
                                  java.lang.Class<T> target)
        Bind the specified target Class using this binder's property sources or create a new instance using the type of the Bindable if the result of the binding is null.
        Type Parameters:
        T - the bound type
        Parameters:
        name - the configuration property name to bind
        target - the target class
        Returns:
        the bound or created object
        Since:
        2.2.0
        See Also:
        bind(ConfigurationPropertyName, Bindable, BindHandler)
      • bindOrCreate

        public <T> T bindOrCreate(ConfigurationPropertyName name,
                                  Bindable<T> target,
                                  BindHandler handler)
        Bind the specified target Bindable using this binder's property sources or create a new instance using the type of the Bindable if the result of the binding is null.
        Type Parameters:
        T - the bound or created type
        Parameters:
        name - the configuration property name to bind
        target - the target bindable
        handler - the bind handler (may be null)
        Returns:
        the bound or created object
        Since:
        2.2.0
      • get

        public static Binder get(org.springframework.core.env.Environment environment)
        Create a new Binder instance from the specified environment.
        Parameters:
        environment - the environment source (must have attached ConfigurationPropertySources)
        Returns:
        a Binder instance
      • get

        public static Binder get(org.springframework.core.env.Environment environment,
                                 BindHandler defaultBindHandler)
        Create a new Binder instance from the specified environment.
        Parameters:
        environment - the environment source (must have attached ConfigurationPropertySources)
        defaultBindHandler - the default bind handler to use if none is specified when binding
        Returns:
        a Binder instance
        Since:
        2.2.0