Revised JSR-303 references to include JSR-349 (Bean Validation 1.1) as well

Issue: SPR-10813
This commit is contained in:
Juergen Hoeller 2013-08-20 22:38:17 +02:00
parent ea6525f15f
commit 5d3d3c111b
1 changed files with 178 additions and 177 deletions

View File

@ -13,12 +13,13 @@
<title>Introduction</title>
<sidebar xml:id="validation-beanvalidation-vs-spring-validation">
<title>JSR-303 Bean Validation</title>
<title>JSR-303/JSR-349 Bean Validation</title>
<para>The Spring Framework supports JSR-303 Bean Validation adapting
<para>Spring Framework 4.0 supports Bean Validation 1.0 (JSR-303) and
Bean Validation 1.1 (JSR-349) in terms of setup support, also adapting
it to Spring's <interfacename>Validator</interfacename> interface.</para>
<para>An application can choose to enable JSR-303 Bean Validation once globally,
<para>An application can choose to enable Bean Validation once globally,
as described in <xref linkend="validation-beanvalidation" />, and use it
exclusively for all validation needs.</para>
@ -1651,33 +1652,33 @@ public class AppConfig {
<para>When an instance of this class is validated by a JSR-303 Validator,
these constraints will be enforced.</para>
<para> For general information on JSR-303, see the <link
xl:href="http://jcp.org/en/jsr/detail?id=303">Bean Validation
Specification</link>. For information on the specific capabilities of
<para>For general information on JSR-303/JSR-349, see the <link
xl:href="http://beanvalidation.org/">Bean Validation website</link>.
For information on the specific capabilities of
the default reference implementation, see the <link
xl:href="https://www.hibernate.org/412.html">Hibernate Validator</link>
documentation. To learn how to setup a JSR-303 implementation as a
documentation. To learn how to setup a Bean Validation provider as a
Spring bean, keep reading.</para>
</section>
<section xml:id="validation-beanvalidation-spring">
<title>Configuring a Bean Validation Implementation</title>
<title>Configuring a Bean Validation Provider</title>
<para> Spring provides full support for the JSR-303 Bean Validation API.
This includes convenient support for bootstrapping a JSR-303
implementation as a Spring bean. This allows for a
<para>Spring provides full support for the Bean Validation API.
This includes convenient support for bootstrapping a JSR-303/JSR-349
Bean Validation provider as a Spring bean. This allows for a
<code>javax.validation.ValidatorFactory</code> or
<code>javax.validation.Validator</code> to be injected wherever
validation is needed in your application.</para>
<para>Use the <classname>LocalValidatorFactoryBean</classname> to
configure a default JSR-303 Validator as a Spring bean: </para>
configure a default Validator as a Spring bean:</para>
<programlisting language="xml"><![CDATA[<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>]]></programlisting>
<para> The basic configuration above will trigger JSR-303 to initialize
using its default bootstrap mechanism. A JSR-303 provider, such as
<para>The basic configuration above will trigger Bean Validation to initialize
using its default bootstrap mechanism. A JSR-303/JSR-349 provider, such as
Hibernate Validator, is expected to be present in the classpath and will
be detected automatically.</para>
@ -1692,7 +1693,7 @@ public class AppConfig {
invoke validation logic.</para>
<para>Inject a reference to <code>javax.validation.Validator</code> if
you prefer to work with the JSR-303 API directly: </para>
you prefer to work with the Bean Validation API directly:</para>
<programlisting language="java"><![CDATA[import javax.validation.Validator;
@ -1720,7 +1721,7 @@ public class MyService {
<section xml:id="validation-beanvalidation-spring-constraints">
<title>Configuring Custom Constraints</title>
<para> Each JSR-303 validation constraint consists of two parts. First,
<para>Each Bean Validation constraint consists of two parts. First,
a @Constraint annotation that declares the constraint and its
configurable properties. Second, an implementation of the
<code>javax.validation.ConstraintValidator</code> interface that
@ -1766,7 +1767,7 @@ public class MyConstraintValidator implements ConstraintValidator {
<para>The default <classname>LocalValidatorFactoryBean</classname>
configuration should prove sufficient for most cases. There are a
number of other configuration options for various JSR-303 constructs,
number of configuration options for various Bean Validation constructs,
from message interpolation to traversal resolution. See the JavaDocs
of <classname>LocalValidatorFactoryBean</classname> for more
information on these options.</para>
@ -1801,7 +1802,7 @@ BindingResult results = binder.getBindingResult();</programlisting>
<interfacename>Validator</interfacename> instances
via <code>dataBinder.addValidators</code>
and <code>dataBinder.replaceValidators</code>.
This is useful when combining globally configured JSR-303 Bean Validation
This is useful when combining globally configured Bean Validation
with a Spring <interfacename>Validator</interfacename> configured
locally on a DataBinder instance.
See <xref linkend="validation-mvc-configuring" />.</para>
@ -1892,16 +1893,16 @@ public class MyController {
</section>
<section xml:id="validation-mvc-jsr303">
<title>Configuring a JSR-303 Validator for use by Spring MVC</title>
<title>Configuring a JSR-303/JSR-349 Validator for use by Spring MVC</title>
<para> With JSR-303, a single <code>javax.validation.Validator</code>
<para>With Bean Validation, a single <code>javax.validation.Validator</code>
instance typically validates <emphasis>all</emphasis> model objects
that declare validation constraints. To configure a JSR-303-backed
Validator with Spring MVC, simply add a JSR-303 Provider, such as
that declare validation constraints. To configure such a JSR-303 backed
Validator with Spring MVC, simply add a Bean Validation provider, such as
Hibernate Validator, to your classpath. Spring MVC will detect it and
automatically enable JSR-303 support across all Controllers. </para>
automatically enable Bean Validation support across all Controllers.</para>
<para> The Spring MVC configuration required to enable JSR-303 support
<para>The Spring MVC configuration required to enable Bean Validation support
is shown below:</para>
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
@ -1914,15 +1915,15 @@ public class MyController {
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- JSR-303 support will be detected on classpath and enabled automatically -->
<!-- JSR-303/JSR-349 support will be detected on classpath and enabled automatically -->
<mvc:annotation-driven/>
</beans>]]></programlisting>
<para> With this minimal configuration, anytime a @Valid @Controller
input is encountered, it will be validated by the JSR-303 provider.
JSR-303, in turn, will enforce any constraints declared against the
input. Any ConstraintViolations will automatically be exposed as
<para>With this minimal configuration, anytime a @Valid @Controller input
is encountered, it will be validated by the Bean Validation provider.
That provider, in turn, will enforce any constraints declared against
the input. Any ConstraintViolations will automatically be exposed as
errors in the BindingResult renderable by standard Spring MVC form
tags.</para>
</section>