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
- Author:
- Phillip Webb, Madhura Bhave
-
Constructor Summary
ConstructorsConstructorDescriptionBinder(Iterable<ConfigurationPropertySource> sources) Create a newBinderinstance for the specified sources.Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver) Create a newBinderinstance for the specified sources.Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, List<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinderinstance for the specified sources.Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, ConversionService conversionService) Create a newBinderinstance for the specified sources.Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, ConversionService conversionService, Consumer<PropertyEditorRegistry> propertyEditorInitializer) Create a newBinderinstance for the specified sources.Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, ConversionService conversionService, Consumer<PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler) Create a newBinderinstance for the specified sources.Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, ConversionService conversionService, Consumer<PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinderinstance for the specified sources.Binder(ConfigurationPropertySource... sources) Create a newBinderinstance for the specified sources. -
Method Summary
Modifier and TypeMethodDescription<T> BindResult<T>Bind the specified targetClassusing this binder'sproperty sources.<T> BindResult<T>Bind the specified targetBindableusing this binder'sproperty sources.<T> BindResult<T>bind(String name, Bindable<T> target, BindHandler handler) Bind the specified targetBindableusing this binder'sproperty sources.<T> BindResult<T>bind(ConfigurationPropertyName name, Bindable<T> target) Bind the specified targetBindableusing this binder'sproperty sources.<T> BindResult<T>bind(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler) Bind the specified targetBindableusing this binder'sproperty sources.<T> TbindOrCreate(String name, Class<T> target) Bind the specified targetClassusing this binder'sproperty sourcesor create a new instance using the type of theBindableif the result of the binding isnull.<T> TbindOrCreate(String name, Bindable<T> target) Bind the specified targetBindableusing this binder'sproperty sourcesor create a new instance using the type of theBindableif the result of the binding isnull.<T> TbindOrCreate(String name, Bindable<T> target, BindHandler handler) Bind the specified targetBindableusing this binder'sproperty sourcesor create a new instance using the type of theBindableif the result of the binding isnull.<T> TbindOrCreate(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler) Bind the specified targetBindableusing this binder'sproperty sourcesor create a new instance using the type of theBindableif the result of the binding isnull.static Binderget(Environment environment) Create a newBinderinstance from the specified environment.static Binderget(Environment environment, BindHandler defaultBindHandler) Create a newBinderinstance from the specified environment.
-
Constructor Details
-
Binder
Create a newBinderinstance for the specified sources. ADefaultFormattingConversionServicewill be used for all conversion.- Parameters:
sources- the sources used for binding
-
Binder
Create a newBinderinstance for the specified sources. ADefaultFormattingConversionServicewill be used for all conversion.- Parameters:
sources- the sources used for binding
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver) Create a newBinderinstance 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, ConversionService conversionService) Create a newBinderinstance for the specified sources.- Parameters:
sources- the sources used for bindingplaceholdersResolver- strategy to resolve any property placeholdersconversionService- the conversion service to convert values (ornullto useApplicationConversionService)
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, ConversionService conversionService, Consumer<PropertyEditorRegistry> propertyEditorInitializer) Create a newBinderinstance for the specified sources.- Parameters:
sources- the sources used for bindingplaceholdersResolver- strategy to resolve any property placeholdersconversionService- the conversion service to convert values (ornullto useApplicationConversionService)propertyEditorInitializer- initializer used to configure the property editors that can convert values (ornullif no initialization is required). Often used to callConfigurableBeanFactory.copyRegisteredEditorsTo(org.springframework.beans.PropertyEditorRegistry).
-
Binder
public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolver placeholdersResolver, ConversionService conversionService, Consumer<PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler) Create a newBinderinstance for the specified sources.- Parameters:
sources- the sources used for bindingplaceholdersResolver- strategy to resolve any property placeholdersconversionService- the conversion service to convert values (ornullto useApplicationConversionService)propertyEditorInitializer- initializer used to configure the property editors that can convert values (ornullif 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, ConversionService conversionService, Consumer<PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinderinstance for the specified sources.- Parameters:
sources- the sources used for bindingplaceholdersResolver- strategy to resolve any property placeholdersconversionService- the conversion service to convert values (ornullto useApplicationConversionService)propertyEditorInitializer- initializer used to configure the property editors that can convert values (ornullif 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<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) Create a newBinderinstance for the specified sources.- Parameters:
sources- the sources used for bindingplaceholdersResolver- strategy to resolve any property placeholdersconversionServices- the conversion services to convert values (ornullto useApplicationConversionService)propertyEditorInitializer- initializer used to configure the property editors that can convert values (ornullif 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 targetClassusing 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 targetBindableusing 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 targetBindableusing 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 targetBindableusing 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 targetBindableusing 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 targetClassusing this binder'sproperty sourcesor create a new instance using the type of theBindableif 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 targetBindableusing this binder'sproperty sourcesor create a new instance using the type of theBindableif 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 targetBindableusing this binder'sproperty sourcesor create a new instance using the type of theBindableif 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 targetBindableusing this binder'sproperty sourcesor create a new instance using the type of theBindableif 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 newBinderinstance from the specified environment.- Parameters:
environment- the environment source (must have attachedConfigurationPropertySources)- Returns:
- a
Binderinstance
-
get
Create a newBinderinstance 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
Binderinstance - Since:
- 2.2.0
-