接口 BindHandler
- 所有已知实现类:
AbstractBindHandler
,BoundPropertiesTrackingBindHandler
,IgnoreErrorsBindHandler
,IgnoreTopLevelConverterNotFoundBindHandler
,NoUnboundElementsBindHandler
,ValidationBindHandler
public interface BindHandler
Callback interface that can be used to handle additional logic during element
binding
.- 从以下版本开始:
- 2.0.0
- 作者:
- Phillip Webb, Madhura Bhave
-
字段概要
字段 -
方法概要
修饰符和类型方法说明default Object
onCreate
(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) Called when binding of an element ends with an unbound result and a newly created instance is about to be returned.default Object
onFailure
(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error) Called when binding fails for any reason (including failures fromonSuccess(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable<?>, org.springframework.boot.context.properties.bind.BindContext, java.lang.Object)
oronCreate(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable<?>, org.springframework.boot.context.properties.bind.BindContext, java.lang.Object)
calls).default void
onFinish
(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) Called when binding finishes with either bound or unbound result.default <T> Bindable
<T> onStart
(ConfigurationPropertyName name, Bindable<T> target, BindContext context) Called when binding of an element starts but before any result has been determined.default Object
onSuccess
(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) Called when binding of an element ends with a successful result.
-
字段详细资料
-
DEFAULT
Default no-op bind handler.
-
-
方法详细资料
-
onStart
default <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) Called when binding of an element starts but before any result has been determined.- 类型参数:
T
- the bindable source type- 参数:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind context- 返回:
- the actual item that should be used for binding (may be
null
)
-
onSuccess
default Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) Called when binding of an element ends with a successful result. Implementations may change the ultimately returned result or perform addition validation.- 参数:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind contextresult
- the bound result (nevernull
)- 返回:
- the actual result that should be used (may be
null
)
-
onCreate
default Object onCreate(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) Called when binding of an element ends with an unbound result and a newly created instance is about to be returned. Implementations may change the ultimately returned result or perform addition validation.- 参数:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind contextresult
- the newly created instance (nevernull
)- 返回:
- the actual result that should be used (must not be
null
) - 从以下版本开始:
- 2.2.2
-
onFailure
default Object onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error) throws Exception Called when binding fails for any reason (including failures fromonSuccess(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable<?>, org.springframework.boot.context.properties.bind.BindContext, java.lang.Object)
oronCreate(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable<?>, org.springframework.boot.context.properties.bind.BindContext, java.lang.Object)
calls). Implementations may choose to swallow exceptions and return an alternative result.- 参数:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind contexterror
- the cause of the error (if the exception stands it may be re-thrown)- 返回:
- the actual result that should be used (may be
null
). - 抛出:
Exception
- if the binding isn't valid
-
onFinish
default void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) throws Exception Called when binding finishes with either bound or unbound result. This method will not be called when binding failed, even if a handler returns a result fromonFailure(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable<?>, org.springframework.boot.context.properties.bind.BindContext, java.lang.Exception)
.- 参数:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind contextresult
- the bound result (may benull
)- 抛出:
Exception
- if the binding isn't valid
-