Generated by GPT-5-mini| Bean Validation | |
|---|---|
| Name | Bean Validation |
| Developer | Oracle Corporation |
| Latest release | Jakarta Bean Validation 3.0 |
| Programming language | Java (programming language) |
| Platform | Java Platform, Enterprise Edition |
| License | Apache License |
Bean Validation
Bean Validation is a specification for declarative constraint validation of Java (programming language) objects, providing a standardized API that integrates with Jakarta EE, Spring Framework, and other application servers. It defines annotations, validator interfaces, and a metadata model enabling reusable, pluggable validation logic for entities, DTOs, and forms across GlassFish, WildFly, Apache TomEE, and Eclipse Jetty environments. The specification is governed by the Jakarta Community Process and has evolved alongside major releases of Java SE and Jakarta EE.
Bean Validation establishes a concise model for applying constraints to properties, parameters, and return values of Java (programming language) beans. It specifies how constraints are declared using annotations, how constraint violations are reported as a set of metadata-rich objects, and how validation providers are discovered via ServiceLoader. The ecosystem includes implementations such as Hibernate (software), which is maintained by Red Hat, and alternative providers used in Payara Server and IBM WebSphere deployments.
The original specification was developed under the Java Community Process as part of the JSR 303 effort, followed by revisions under JSR 349 and JSR 380 which aligned with Java SE 7 and Java SE 8 features respectively. Subsequent evolution moved into the Eclipse Foundation and the Jakarta EE umbrella, producing Jakarta Bean Validation 2.0 and Jakarta Bean Validation 3.0 to coordinate with Jakarta EE 8 and Jakarta EE 9. Each version added new features, clearer metadata handling, and tighter integration points for method-level validation used by frameworks like Spring Framework and Micronaut.
The API centers on a few primary concepts: constraints declared via annotations, the Validator interface for programmatic validation, and the ConstraintViolation object for reporting problems. The specification defines a ValidationFactory bootstrap process, commonly realized through Validation.buildDefaultValidatorFactory(), which binds to provider implementations such as Hibernate Validator. It prescribes metadata for groups, payloads, and default messages, and integrates with BeanDescriptor models used by containers including JBoss EAP and Oracle GlassFish Server to reflect constraint metadata at runtime.
Standard constraints include annotations that mirror common domain requirements: @NotNull for null checks, @Size for collection and string cardinality, @Min and @Max for numeric bounds, and @Pattern for regular-expression matching. Implementations provide built-in validators that handle types such as String (computer science), java.util.Collection, java.util.Map, primitive wrappers like Integer (computer science), and temporal types introduced by JSR 310 such as java.time.LocalDate and java.time.Instant. Internationalization support is enabled through resource bundles and integration with locale-aware servers like Apache Tomcat.
Bean Validation integrates tightly with persistence, presentation, and remoting layers. In object-relational mapping contexts it works with Jakarta Persistence API providers like Hibernate ORM to enforce constraints before database operations, and with Spring MVC and Jakarta Faces for form-backed bean validation during data binding. Containers such as WildFly, GlassFish, and Payara Server wire validation into lifecycle events and injection mechanisms defined by CDI (Contexts and Dependency Injection). Interceptors for method validation are used in frameworks like Spring Security and Apache CXF to validate service endpoints.
Developers extend the model by defining custom constraint annotations and corresponding ConstraintValidator implementations, registered via ServiceLoader or programmatic configuration in provider-specific bootstrap code. Advanced use cases include composing constraints from existing ones, using validation groups to control execution order, and writing cross-parameter or class-level validators for complex invariants enforced in applications like Eclipse IDE plug-ins or enterprise systems built on IBM Liberty. Integration points allow constraint payloads to carry metadata consumed by frameworks such as Quarkus and Micronaut.
Typical examples include DTO validation in REST APIs built with JAX-RS implementations such as RESTEasy or Jersey, server-side form validation with Jakarta Faces, and automatic constraint checking in services using Spring Boot starters. Use cases span from simple input validation in microservices deployed on Kubernetes clusters to complex business-rule enforcement in financial systems running on Oracle WebLogic Server or IBM WebSphere Liberty. Validation also aids code generation tools and schema-first workflows in projects leveraging OpenAPI Specification and Swagger tooling to ensure runtime contracts match API documentation.
Category:Java specifications