> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/35.-validation.md).

# 35. 验证

只要在类路径上存在JSR-303实现（比如Hibernate validator），Bean Validation 1.1支持的方法验证特性就会自动启用。这允许bean方法的参数和/或者返回值，被标注为`javax.validation`约束。为了让这样的带标注的方法在搜索行内约束标注时被找到，拥有它们的目标类，需要在类型层次上被标注为`@Validated`。

例如，下面的服务触发第一个参数的验证，确保它的大小在8和10之间：

```java
@Service
@Validated
public class MyBean {

    public Archive findByCodeAndAuthor(@Size(min = 8, max = 10) String code,
            Author author) {
        ...
    }

}
```
