To ensure compatibility of Hibernate Validator with Tomcat 7, it is recommended to downgrade Hibernate Validator to version 5.4.3.Final. This version aligns with the requirements of Tomcat 7, which supports Bean Validation 1.1 (JSR 349) and Expression Language (EL) 2.2. Here’s how to implement this in your Maven project:
Step 1: Update Your pom.xml
Add the following dependency for Hibernate Validator:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.3.Final</version>
</dependency>
Step 2: Add the EL API Dependency
Since Tomcat 7 includes EL 2.2, you may also need to add the EL API dependency to your pom.xml
to avoid potential NoClassDefFoundError
issues:
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
Compatibility Overview
- Hibernate Validator 5.x: Supports Bean Validation 1.1 (JSR 349) and EL 2.2.
- Hibernate Validator 6.x: Requires Bean Validation 2.0 (JSR 380) and EL 3.0, which is not compatible with Tomcat 7.
Additional Considerations
When using Hibernate Validator 5.x with Tomcat 7, ensure that your environment is consistent with the following requirements:
- Servlet: 3.0
- JSP: 2.2
- JDK: 6 or higher
By following these steps, you can effectively use Hibernate Validator with Tomcat 7 without encountering compatibility issues.
Citations:
[1] https://hibernate.org/validator/releases/
[2] https://stackoverflow.com/questions/71650918/how-to-ensure-hibernate-dependencies-are-compatible-without-springboot
[3] https://beanvalidation.org/1.1/
[4] https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
[5] https://stackoverflow.com/questions/49385257/tomcat-7-java-lang-noclassdeffounderror-javax-el-elmanager
[6] https://hibernate.org/validator/releases/5.3/
[7] https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/