polish
This commit is contained in:
parent
90697e884d
commit
5c525e546c
|
|
@ -1230,7 +1230,7 @@ public interface FormatterRegistry {
|
||||||
<programlisting language="java"><![CDATA[
|
<programlisting language="java"><![CDATA[
|
||||||
public class Person {
|
public class Person {
|
||||||
private String name;
|
private String name;
|
||||||
private int age;
|
private int age;
|
||||||
}]]>
|
}]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
|
|
@ -1249,12 +1249,12 @@ public class Person {
|
||||||
}]]>
|
}]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
When this object is processed by a JSR-303 Validator, these constraints will be validated.
|
When an instance of this class is validated by a JSR-303 Validator, these constraints will be enforced.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
For general information on JSR-303, see the <ulink url="http://jcp.org/en/jsr/detail?id=303">Bean Validation Specification</ulink>.
|
For general information on JSR-303, see the <ulink url="http://jcp.org/en/jsr/detail?id=303">Bean Validation Specification</ulink>.
|
||||||
For information on the specific capabilities of the default reference implementation, see the <ulink url="https://www.hibernate.org/412.html">Hibernate Validator</ulink> documentation.
|
For information on the specific capabilities of the default reference implementation, see the <ulink url="https://www.hibernate.org/412.html">Hibernate Validator</ulink> documentation.
|
||||||
For how to setup a JSR-303 implementation as a Spring bean, keep reading.
|
To learn how to setup a JSR-303 implementation as a Spring bean, keep reading.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
<section id="validation.beanvalidation.spring">
|
<section id="validation.beanvalidation.spring">
|
||||||
|
|
@ -1262,7 +1262,7 @@ public class Person {
|
||||||
<para>
|
<para>
|
||||||
Spring provides full support for the JSR-303 Bean Validation API.
|
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 includes convenient support for bootstrapping a JSR-303 implementation as a Spring bean.
|
||||||
This allows a <code>javax.validation.Validator</code> to be injected wherever validation is needed.
|
This allows a <code>javax.validation.Validator</code> to be injected wherever validation is needed in your application.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Use the LocalValidatorFactoryBean to configure a default JSR-303 Validator as a Spring bean:
|
Use the LocalValidatorFactoryBean to configure a default JSR-303 Validator as a Spring bean:
|
||||||
|
|
@ -1272,13 +1272,13 @@ public class Person {
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
The basic configuration above will trigger JSR-303 to initialize using its default bootstrap mechanism.
|
The basic configuration above will trigger JSR-303 to initialize using its default bootstrap mechanism.
|
||||||
The JSR-303 provider, such as Hibernate Validator, will be detected in your classpath automatically.
|
A JSR-303 provider, such as Hibernate Validator, is expected to be present in the classpath and will be detected automatically.
|
||||||
</para>
|
</para>
|
||||||
<section id="validation.beanvalidation.spring.inject">
|
<section id="validation.beanvalidation.spring.inject">
|
||||||
<title>Injecting a Validator</title>
|
<title>Injecting a Validator</title>
|
||||||
<para>
|
<para>
|
||||||
LocalValidatorFactoryBean implements <code>javax.validation.Validator</code> as well as <code>org.springframework.validation.Validator</code>.
|
LocalValidatorFactoryBean implements both <code>javax.validation.Validator</code> and <code>org.springframework.validation.Validator</code>.
|
||||||
Once created, you may inject a reference to either of these interfaces to other beans that need to invoke JSR-303 validation logic.
|
Inject a reference to one of these two interfaces into beans that need to invoke validation logic.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Inject a reference to <code>javax.validation.Validator</code> if you prefer to work with the JSR-303 API directly:
|
Inject a reference to <code>javax.validation.Validator</code> if you prefer to work with the JSR-303 API directly:
|
||||||
|
|
@ -1295,7 +1295,7 @@ public class MyService {
|
||||||
}]]>
|
}]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
Inject a reference to <code>org.springframework.validation.Validator</code> if you prefer to work with the familiar Spring Validation API:
|
Inject a reference to <code>org.springframework.validation.Validator</code> if your bean depends on the existing Spring Validation API:
|
||||||
</para>
|
</para>
|
||||||
<programlisting language="java"><![CDATA[
|
<programlisting language="java"><![CDATA[
|
||||||
import org.springframework.validation.Validator;
|
import org.springframework.validation.Validator;
|
||||||
|
|
@ -1340,8 +1340,12 @@ public class MyConstraintValidator implements ConstraintValidator {
|
||||||
@Autowired;
|
@Autowired;
|
||||||
private Foo aDependency;
|
private Foo aDependency;
|
||||||
|
|
||||||
|
...
|
||||||
}]]>
|
}]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
As you can see, the ConstraintValidator implementation above can have its dependencies @Autowired by Spring like any other bean.
|
||||||
|
</para>
|
||||||
</section>
|
</section>
|
||||||
<section id="validation.beanvalidation.spring.other">
|
<section id="validation.beanvalidation.spring.other">
|
||||||
<title>Additional Configuration Options</title>
|
<title>Additional Configuration Options</title>
|
||||||
|
|
@ -1447,7 +1451,7 @@ public class MyController {
|
||||||
<para>
|
<para>
|
||||||
With JSR-303, the default <code>javax.validation.Validator</code> implementation is quite generic.
|
With JSR-303, the default <code>javax.validation.Validator</code> implementation is quite generic.
|
||||||
A single instance typically coordinates the validation of <emphasis>all</emphasis> application objects that declare validation constraints.
|
A single instance typically coordinates the validation of <emphasis>all</emphasis> application objects that declare validation constraints.
|
||||||
To configure such a Validator for use by Spring MVC, simply inject a <code>LocalValidatorFactoryBean</code> reference into the <code>WebBindingInitializer</code> as shown in the previous section.
|
To configure such a Validator for use by Spring MVC, simply inject a <code>LocalValidatorFactoryBean</code> reference into the <code>WebBindingInitializer</code>.
|
||||||
<code>LocalValidatorFactoryBean</code> already implements <code>org.springframework.validation.Validation</code>, delegating to the JSR-303 provider underneath.
|
<code>LocalValidatorFactoryBean</code> already implements <code>org.springframework.validation.Validation</code>, delegating to the JSR-303 provider underneath.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
|
|
@ -1468,7 +1472,7 @@ public class MyController {
|
||||||
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />]]>
|
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
With this configuration, anytime a @Valid @Controller method argument is encountered, it will be validated using JSR-303.
|
With this configuration, anytime a @Valid @Controller method argument is encountered, it will be validated using the JSR-303 provider.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue