Class Binder
java.lang.Object
org.springframework.boot.context.properties.bind.Binder
A container object which Binds objects from one or more
ConfigurationPropertySources
.- Since:
- 2.0.0
-
Constructor Summary
ConstructorDescriptionBinder
(Iterable<ConfigurationPropertySource> sources) Create a newBinder
instance for the specified sources.Binder
(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver) Create a newBinder
instance for the specified sources.Binder
(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, List<org.springframework.core.convert.ConversionService> conversionServices, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinder
instance for the specified sources.Binder
(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService) Create a newBinder
instance for the specified sources.Binder
(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer) Create a newBinder
instance for the specified sources.Binder
(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler) Create a newBinder
instance for the specified sources.Binder
(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinder
instance for the specified sources.Binder
(ConfigurationPropertySource... sources) Create a newBinder
instance for the specified sources. -
Method Summary
Modifier and TypeMethodDescription<T> BindResult<T>
Bind the specified targetClass
using this binder'sproperty sources
.<T> BindResult<T>
Bind the specified targetBindable
using this binder'sproperty sources
.<T> BindResult<T>
bind
(String name, Bindable<T> target, BindHandler handler) Bind the specified targetBindable
using this binder'sproperty sources
.<T> BindResult<T>
bind
(ConfigurationPropertyName name, Bindable<T> target) Bind the specified targetBindable
using this binder'sproperty sources
.<T> BindResult<T>
bind
(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler) Bind the specified targetBindable
using this binder'sproperty sources
.<T> T
bindOrCreate
(String name, Class<T> target) Bind the specified targetClass
using this binder'sproperty sources
or create a new instance of the specified targetClass
if the result of the binding isnull
.<T> T
bindOrCreate
(String name, Bindable<T> target) Bind the specified targetBindable
using this binder'sproperty sources
or create a new instance using the type of theBindable
if the result of the binding isnull
.<T> T
bindOrCreate
(String name, Bindable<T> target, BindHandler handler) Bind the specified targetBindable
using this binder'sproperty sources
or create a new instance using the type of theBindable
if the result of the binding isnull
.<T> T
bindOrCreate
(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler) Bind the specified targetBindable
using this binder'sproperty sources
or create a new instance using the type of theBindable
if the result of the binding isnull
.static Binder
get
(org.springframework.core.env.Environment environment) Create a newBinder
instance from the specified environment.static Binder
get
(org.springframework.core.env.Environment environment, BindHandler defaultBindHandler) Create a newBinder
instance from the specified environment.
-
Constructor Details
-
Binder
Create a newBinder
instance for the specified sources. ADefaultFormattingConversionService
will be used for all conversion.- Parameters:
sources
- the sources used for binding
-
Binder
Create a newBinder
instance for the specified sources. ADefaultFormattingConversionService
will be used for all conversion.- Parameters:
sources
- the sources used for binding
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver) Create a newBinder
instance for the specified sources.- Parameters:
sources
- the sources used for bindingplaceholdersResolver
- strategy to resolve any property placeholders
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService) Create a newBinder
instance for the specified sources.- Parameters:
sources
- the sources used for bindingplaceholdersResolver
- strategy to resolve any property placeholdersconversionService
- the conversion service to convert values (ornull
to useApplicationConversionService
)
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer) Create a newBinder
instance for the specified sources.- Parameters:
sources
- the sources used for bindingplaceholdersResolver
- strategy to resolve any property placeholdersconversionService
- the conversion service to convert values (ornull
to useApplicationConversionService
)propertyEditorInitializer
- initializer used to configure the property editors that can convert values (ornull
if no initialization is required). Often used to callConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry)
.
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler) Create a newBinder
instance for the specified sources.- Parameters:
sources
- the sources used for bindingplaceholdersResolver
- strategy to resolve any property placeholdersconversionService
- the conversion service to convert values (ornull
to useApplicationConversionService
)propertyEditorInitializer
- initializer used to configure the property editors that can convert values (ornull
if no initialization is required). Often used to callConfigurableBeanFactory.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(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, org.springframework.core.convert.ConversionService conversionService, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinder
instance for the specified sources.- Parameters:
sources
- the sources used for bindingplaceholdersResolver
- strategy to resolve any property placeholdersconversionService
- the conversion service to convert values (ornull
to useApplicationConversionService
)propertyEditorInitializer
- initializer used to configure the property editors that can convert values (ornull
if no initialization is required). Often used to callConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry)
.defaultBindHandler
- the default bind handler to use if none is specified when bindingconstructorProvider
- the constructor provider which provides the bind constructor to use when binding- Since:
- 2.2.1
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, List<org.springframework.core.convert.ConversionService> conversionServices, Consumer<org.springframework.beans.PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinder
instance for the specified sources.- Parameters:
sources
- the sources used for bindingplaceholdersResolver
- strategy to resolve any property placeholdersconversionServices
- the conversion services to convert values (ornull
to useApplicationConversionService
)propertyEditorInitializer
- initializer used to configure the property editors that can convert values (ornull
if no initialization is required). Often used to callConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry)
.defaultBindHandler
- the default bind handler to use if none is specified when bindingconstructorProvider
- the constructor provider which provides the bind constructor to use when binding- Since:
- 2.5.0
-
-
Method Details
-
bind
Bind the specified targetClass
using this binder'sproperty sources
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target class- Returns:
- the binding result (never
null
) - See Also:
-
bind
Bind the specified targetBindable
using this binder'sproperty sources
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target bindable- Returns:
- the binding result (never
null
) - See Also:
-
bind
Bind the specified targetBindable
using this binder'sproperty sources
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target bindable- Returns:
- the binding result (never
null
) - See Also:
-
bind
Bind the specified targetBindable
using this binder'sproperty sources
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target bindablehandler
- the bind handler (may benull
)- Returns:
- the binding result (never
null
)
-
bind
public <T> BindResult<T> bind(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler) Bind the specified targetBindable
using this binder'sproperty sources
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target bindablehandler
- the bind handler (may benull
)- Returns:
- the binding result (never
null
)
-
bindOrCreate
Bind the specified targetClass
using this binder'sproperty sources
or create a new instance of the specified targetClass
if the result of the binding isnull
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target class- Returns:
- the bound or created object
- Since:
- 2.2.0
- See Also:
-
bindOrCreate
Bind the specified targetBindable
using this binder'sproperty sources
or create a new instance using the type of theBindable
if the result of the binding isnull
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target bindable- Returns:
- the bound or created object
- Since:
- 2.2.0
- See Also:
-
bindOrCreate
Bind the specified targetBindable
using this binder'sproperty sources
or create a new instance using the type of theBindable
if the result of the binding isnull
.- Type Parameters:
T
- the bound type- Parameters:
name
- the configuration property name to bindtarget
- the target bindablehandler
- the bind handler- Returns:
- the bound or created object
- Since:
- 2.2.0
- See Also:
-
bindOrCreate
Bind the specified targetBindable
using this binder'sproperty sources
or create a new instance using the type of theBindable
if the result of the binding isnull
.- Type Parameters:
T
- the bound or created type- Parameters:
name
- the configuration property name to bindtarget
- the target bindablehandler
- the bind handler (may benull
)- Returns:
- the bound or created object
- Since:
- 2.2.0
-
get
Create a newBinder
instance from the specified environment.- Parameters:
environment
- the environment source (must have attachedConfigurationPropertySources
)- Returns:
- a
Binder
instance
-
get
public static Binder get(org.springframework.core.env.Environment environment, BindHandler defaultBindHandler) Create a newBinder
instance from the specified environment.- Parameters:
environment
- the environment source (must have attachedConfigurationPropertySources
)defaultBindHandler
- the default bind handler to use if none is specified when binding- Returns:
- a
Binder
instance - Since:
- 2.2.0
-