diff --git a/framework-docs/modules/ROOT/partials/web/web-data-binding-model-design.adoc b/framework-docs/modules/ROOT/partials/web/web-data-binding-model-design.adoc index bd29449c4b2..0a8b53c5168 100644 --- a/framework-docs/modules/ROOT/partials/web/web-data-binding-model-design.adoc +++ b/framework-docs/modules/ROOT/partials/web/web-data-binding-model-design.adoc @@ -28,8 +28,6 @@ For example: } ---- - - NOTE: It is also possible to configure `disallowedFields`, but that's fragile, and due to be https://github.com/spring-projects/spring-framework/issues/36802[deprecated] in Spring Framework 7.1. It is easy to miss or add others over time that should also be excluded. @@ -38,4 +36,17 @@ By default, `DataBinder` applies both constructor and setter binding. This is fine with immutable objects and dedicated objects, but for domain objects, you must remember to declare `allowFields`. To ensure data binding is only used in declarative style where expected inputs are explicitly declared, you can set `declarativeBinding=true` on `DataBinder`. -In this mode, `DataBinding` applies constructor binding, and additionally setter binding if `allowedFields` is set. \ No newline at end of file +In this mode, `DataBinding` applies constructor binding, and additionally setter binding if `allowedFields` is set. +The below shows how to set this flag globally: + +[source,java,indent=0,subs="verbatim,quotes"] +---- + @ControllerAdvice + public class ControllerConfig { + + @InitBinder + void initBinder(WebDataBinder binder) { + binder.setDeclarativeBinding(true); + } + } +----