- 校验场景
- 问题描述
- 使用当地方法手动检查手动检查
- 解决方法
1.校验场景
- 校验实体类
package henu.soft.xiaosi.product.entity;import com.baomidou.mybatisplus.annotation.TableId;import com.baomidou.mybatisplus.annotation.TableName;import java.io.Serializable;import lombok.Data;import javax.validation.constraints.NotBlank;import javax.validation.constraints.NotEmpty;import javax.validation.constraints.NotNull;/** * 品牌 * * @author xiaosi * @email 2589165806@qq.com * @date 2021-07-22 21:04:34 */@Data@TableName("pms_brand")public class BrandEntity implements Serializable {private static final long serialVersionUID = 1L;/** * 品牌id */@TableIdprivate Long brandId;/** * 品牌名 */@NotBlank(message = "品牌名称不能为空!")private String name;/** * 品牌logo地址 */@NotEmpty(message = “logo不能为空!")private String logo;/** * 介绍 */private String descript;/** * 显示状态[0-不显示;1-显示] */private Integer showStatus;/** * 检索首字母 */@NotNull(message = “检索首字母不能为空!")private String firstLetter;/** * 排序 */private Integer sort;}
- 验controler
/** * 保存 */ @RequestMapping("/save") @RequiresPermissions("product:brand:save") public R save( @RequestBody @Valid BrandEntity brand){ // 统一全局处理异常校验异常统一全局处理 /* if(result.hasErrors()){ List<FieldError> fieldErrors = result.getFieldErrors(); Map<String,String> map = new HashMap<>(); fieldErrors.forEach((item)->{ String field = item.getField(); String msg = item.getDefaultMessage(); map.put(field,msg); }); return R.error(400,”信息验证错误!").put("data",map); } else{ brandService.save(brand); return R.ok(); } */ brandService.save(brand); return R.ok(); }
2.问题描述启动试验发现校验不生效
开始依赖
<!-- JSR303校验--><!-- <dependency>--><!-- <groupId>jakarta.validation</groupId>--><!-- <artifactId>jakarta.validation-api</artifactId>--><!-- <version>3.0.0</version>--><!-- </dependency>--><!-- <dependency>--><!-- <groupId>org.hibernate</groupId>--><!-- <artifactId>hibernate-validator</artifactId>--><!-- <version>5.2.4.Final</version>--><!-- </dependency>-->
2.使用本地方法进行检验package henu.soft.xiaosi.product.util;import henu.soft.xiaosi.product.entity.BrandEntity;import org.apache.commons.collections.CollectionUtils;import javax.validation.ConstraintViolation;import javax.validation.Validation;import javax.validation.Validator;import java.util.HashMap;import java.util.Map;import java.util.Set;public class ValidateUtil { private static Validator validator = Validation.buildDefaultValidatorFactory() .getValidator(); public static void beanValidate(Object obj) throws Exception { Map<String, String> validatedMsg = new HashMap<>(); Set<ConstraintViolation<Object>> constraintViolations = validator.validate(obj); for (ConstraintViolation<Object> c : constraintViolations) { validatedMsg.put(c.getPropertyPath().toString(), c.getMessage()); } if (CollectionUtils.isNotEmpty(constraintViolations)) { throw new Exception(String.valueOf(validatedMsg)); } } public static void main(String[] args) throws Exception { beanValidate(new BrandEntity()); }}
控制台报错的结果
javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classp
然后在stackoverflow上找到类似的问题
导入依赖后进行测试,控制台报错
13:23:50.303 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2logerprovider13:23:50.310 [main] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 5.2.4.Final13:23:50.340 [main] DEBUG org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/ValidationExceptionat java.base/java.lang.ClassLoader.defineclass1(Native Method)at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:129)at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:96)at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:31)at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:296)at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:103)at henu.soft.xiaosi.product.util.ValidateUtil.<clinit>(ValidateUtil.java:14)Caused by: java.lang.ClassNotFoundException: javax.xml.bind.ValidationExceptionat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)... 15 more
Classnotfound是Classnotfound的异常,重新取代高版本的依赖再试
去maven中心仓库:https://mvnrepository.com/artifact/org.hibernate/hibernate-validator
在高版本中导入hibernate。-validator,再次测试
终于验证成功了!!!
"C:\Program Files\Java\jdk-11.0.7\bin\java.exe" "-javaagent:E:\IDEA\IntelliJ IDEA 2020.1.2\lib\idea_rt.jar=1038:E:\IDEA\IntelliJ IDEA 2020.1.2\bin" -Dfile.encoding=UTF-8 -classpath E:\项目\guli-shop\guli-shop-product\target\classes;E:\项目\guli-shop\guli-shop-common\target\classes;E:\Maven\MavenLocalRepository\maven_repository\org\hibernate\validator\hibernate-validator\6.2.0.Final\hibernate-validator-6.2.0.Final.jar;E:\Maven\MavenLocalRepository\maven_repository\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\jboss\logging\jboss-logging\3.4.2.Final\jboss-logging-3.4.2.Final.jar;E:\Maven\MavenLocalRepository\maven_repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\baomidou\mybatis-plus-boot-starter\3.4.2\mybatis-plus-boot-starter-3.4.2.jar;E:\Maven\MavenLocalRepository\maven_repository\com\baomidou\mybatis-plus\3.4.2\mybatis-plus-3.4.2.jar;E:\Maven\MavenLocalRepository\maven_repository\com\baomidou\mybatis-plus-extension\3.4.2\mybatis-plus-extension-3.4.2.jar;E:\Maven\MavenLocalRepository\maven_repository\com\baomidou\mybatis-plus-core\3.4.2\mybatis-plus-core-3.4.2.jar;E:\Maven\MavenLocalRepository\maven_repository\com\baomidou\mybatis-plus-annotation\3.4.2\mybatis-plus-annotation-3.4.2.jar;E:\Maven\MavenLocalRepository\maven_repository\com\github\jsqlparser\jsqlparser\4.0\jsqlparser-4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\mybatis\mybatis\3.5.6\mybatis-3.5.6.jar;E:\Maven\MavenLocalRepository\maven_repository\org\mybatis\mybatis-spring\2.0.5\mybatis-spring-2.0.5.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-autoconfigure\2.5.2\spring-boot-autoconfigure-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-starter-jdbc\2.5.2\spring-boot-starter-jdbc-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-jdbc\5.3.8\spring-jdbc-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-tx\5.3.8\spring-tx-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\projectlombok\lombok\1.18.20\lombok-1.18.20.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-spring\1.4.0\shiro-spring-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-core\1.4.0\shiro-core-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-lang\1.4.0\shiro-lang-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-cache\1.4.0\shiro-cache-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-crypto-hash\1.4.0\shiro-crypto-hash-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-crypto-core\1.4.0\shiro-crypto-core-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-crypto-cipher\1.4.0\shiro-crypto-cipher-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-config-core\1.4.0\shiro-config-core-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-config-ogdl\1.4.0\shiro-config-ogdl-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-event\1.4.0\shiro-event-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\shiro\shiro-web\1.4.0\shiro-web-1.4.0.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\httpcomponents\httpcore\4.4.14\httpcore-4.4.14.jar;E:\Maven\MavenLocalRepository\maven_repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-web\5.3.8\spring-web-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-beans\5.3.8\spring-beans-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-webmvc\5.3.8\spring-webmvc-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-aop\5.3.8\spring-aop-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-context\5.3.8\spring-context-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-expression\5.3.8\spring-expression-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\mysql\mysql-connector-java\8.0.25\mysql-connector-java-8.0.25.jar;E:\Maven\MavenLocalRepository\maven_repository\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-discovery\2.2.5.RELEASE\spring-cloud-starter-alibaba-nacos-discovery-2.2.5.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\com\alibaba\cloud\spring-cloud-alibaba-commons\2.2.5.RELEASE\spring-cloud-alibaba-commons-2.2.5.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\com\alibaba\nacos\nacos-client\1.4.1\nacos-client-1.4.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\alibaba\nacos\nacos-common\1.4.1\nacos-common-1.4.1.jar;E:\Maven\MavenLocalRepository\maven_repository\commons-io\commons-io\2.2\commons-io-2.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\httpcomponents\httpasyncclient\4.1.4\httpasyncclient-4.1.4.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\httpcomponents\httpcore-nio\4.4.14\httpcore-nio-4.4.14.jar;E:\Maven\MavenLocalRepository\maven_repository\com\alibaba\nacos\nacos-api\1.4.1\nacos-api-1.4.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\google\guava\guava\24.1.1-jre\guava-24.1.1-jre.jar;E:\Maven\MavenLocalRepository\maven_repository\com\google\code\findbugsjsr305\1.3.9\jsr305-1.3.9.jar;E:\Maven\MavenLocalRepository\maven_repository\org\checkerframework\checker-compat-qual\2.0.0\checker-compat-qual-2.0.0.jar;E:\Maven\MavenLocalRepository\maven_repository\com\google\errorprone\error_prone_annotations\2.1.3\error_prone_annotations-2.1.3.jar;E:\Maven\MavenLocalRepository\maven_repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar;E:\Maven\MavenLocalRepository\maven_repository\org\codehaus\mojo\animal-sniffer-annotations\1.14\animal-sniffer-annotations-1.14.jar;E:\Maven\MavenLocalRepository\maven_repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;E:\Maven\MavenLocalRepository\maven_repository\com\fasterxml\jackson\core\jackson-core\2.12.3\jackson-core-2.12.3.jar;E:\Maven\MavenLocalRepository\maven_repository\io\prometheus\simpleclient\0.5.0\simpleclient-0.5.0.jar;E:\Maven\MavenLocalRepository\maven_repository\com\alibaba\spring\spring-context-support\1.0.10\spring-context-support-1.0.10.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-context\3.0.3\spring-cloud-context-3.0.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.2.5.RELEASE\spring-cloud-starter-netflix-ribbon-2.2.5.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-netflix-ribbon\2.2.5.RELEASE\spring-cloud-netflix-ribbon-2.2.5.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-netflix-archaius\2.2.5.RELEASE\spring-cloud-netflix-archaius-2.2.5.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.2.5.RELEASE\spring-cloud-starter-netflix-archaius-2.2.5.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;E:\Maven\MavenLocalRepository\maven_repository\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\ribbon\ribbon\2.3.0\ribbon-2.3.0.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\ribbon\ribbon-transport\2.3.0\ribbon-transport-2.3.0.jar;E:\Maven\MavenLocalRepository\maven_repository\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;E:\Maven\MavenLocalRepository\maven_repository\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\hystrix\hystrix-core\1.4.3\hystrix-core-1.4.3.jar;E:\Maven\MavenLocalRepository\maven_repository\javax\inject\javax.inject\1\javax.inject-1.jar;E:\Maven\MavenLocalRepository\maven_repository\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\ribbon\ribbon-core\2.3.0\ribbon-core-2.3.0.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\ribbon\ribbon-httpclient\2.3.0\ribbon-httpclient-2.3.0.jar;E:\Maven\MavenLocalRepository\maven_repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;E:\Maven\MavenLocalRepository\maven_repository\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;E:\Maven\MavenLocalRepository\maven_repository\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\sun\jersey\contribs\jersey-apache-client4.19.1jersey-apache-client4-1.19.19.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\servo\servo-core\0.10.1\servo-core-0.10.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\servo\servo-internal\0.10.1\servo-internal-0.10.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\netflix-commons\netflix-commons-util\0.1.1\netflix-commons-util-0.1.1.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\ribbon\ribbon-loadbalancer\2.3.0\ribbon-loadbalancer-2.3.0.jar;E:\Maven\MavenLocalRepository\maven_repository\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;E:\Maven\MavenLocalRepository\maven_repository\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-config\2.2.5.RELEASE\spring-cloud-starter-alibaba-nacos-config-2.2.5.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-starter-web\2.5.2\spring-boot-starter-web-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-starter\2.5.2\spring-boot-starter-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot\2.5.2\spring-boot-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-starter-logging\2.5.2\spring-boot-starter-logging-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\Maven\MavenLocalRepository\maven_repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\logging\log4j\log4j-to-slf4j2.14.1j-to-slf4j-2.14.1.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\logging\log4j\log4j-api2.14.1j-api-2.14.1.jar;E:\Maven\MavenLocalRepository\maven_repository\org\slf4j\jul-to-slf4j\1.7.31\jul-to-slf4j-1.7.31.jar;E:\Maven\MavenLocalRepository\maven_repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\Maven\MavenLocalRepository\maven_repository\org\yaml\snakeyaml\1.28\snakeyaml-1.28.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-starter-json\2.5.2\spring-boot-starter-json-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\com\fasterxml\jackson\core\jackson-databind\2.12.3\jackson-databind-2.12.3.jar;E:\Maven\MavenLocalRepository\maven_repository\com\fasterxml\jackson\core\jackson-annotations\2.12.3\jackson-annotations-2.12.3.jar;E:\Maven\MavenLocalRepository\maven_repository\com\fasterxml\jackson\datatype\jackson-datatype-2.12.3jdk8jackson-datatype-jdk8-2.12.3.jar;E:\Maven\MavenLocalRepository\maven_repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.12.3jackson-datatype-jsr310-2.12.3.jar;E:\Maven\MavenLocalRepository\maven_repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.12.3\jackson-module-parameter-names-2.12.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-starter-tomcat\2.5.2\spring-boot-starter-tomcat-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.48\tomcat-embed-core-9.0.48.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.48\tomcat-embed-el-9.0.48.jar;E:\Maven\MavenLocalRepository\maven_repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.48\tomcat-embed-websocket-9.0.48.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-starter-openfeign\3.0.3\spring-cloud-starter-openfeign-3.0.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-starter\3.0.3\spring-cloud-starter-3.0.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\security\spring-security-rsa\1.0.10.RELEASE\spring-security-rsa-1.0.10.RELEASE.jar;E:\Maven\MavenLocalRepository\maven_repository\org\bouncycastle\bcpkix-jdk15on\1.68bcpkix-jdk15on-1.68.jar;E:\Maven\MavenLocalRepository\maven_repository\org\bouncycastle\bcprov-jdk15on\1.68bcprov-jdk15on-1.68.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-openfeign-core\3.0.3\spring-cloud-openfeign-core-3.0.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\boot\spring-boot-starter-aop\2.5.2\spring-boot-starter-aop-2.5.2.jar;E:\Maven\MavenLocalRepository\maven_repository\org\aspectj\aspectjweaver\1.9.6\aspectjweaver-1.9.6.jar;E:\Maven\MavenLocalRepository\maven_repository\io\github\openfeign\form\feign-form-spring\3.8.0\feign-form-spring-3.8.0.jar;E:\Maven\MavenLocalRepository\maven_repository\io\github\openfeign\form\feign-form\3.8.0\feign-form-3.8.0.jar;E:\Maven\MavenLocalRepository\maven_repository\commons-fileupload\commons-fileupload\1.4\commons-fileupload-1.4.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\cloud\spring-cloud-commons\3.0.3\spring-cloud-commons-3.0.3.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\security\spring-security-crypto\5.5.1\spring-security-crypto-5.5.1.jar;E:\Maven\MavenLocalRepository\maven_repository\io\github\openfeign\feign-core\10.12\feign-core-10.12.jar;E:\Maven\MavenLocalRepository\maven_repository\io\github\openfeign\feign-slf4j\10.12\feign-slf4j-10.12.jar;E:\Maven\MavenLocalRepository\maven_repository\org\slf4j\slf4j-api\1.7.31\slf4j-api-1.7.31.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-core\5.3.8\spring-core-5.3.8.jar;E:\Maven\MavenLocalRepository\maven_repository\org\springframework\spring-jcl\5.3.8\spring-jcl-5.3.8.jar henu.soft.xiaosi.product.util.Validateutil13:33:13.428 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2logerprovider13:33:13.436 [main] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.2.0.Final13:33:13.443 [main] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.13:33:13.445 [main] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL13:33:13.446 [main] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader13:33:13.446 [main] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.13:33:13.454 [main] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.13:33:13.495 [main] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL13:33:13.658 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000252: Using org.hibernate.validator.internal.engine.DefaultPropertyNodeNameProvider as property node name provider.13:33:13.666 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.13:33:13.666 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.13:33:13.667 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.13:33:13.667 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.13:33:13.667 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.Exception in thread "main" java.lang.Exception: {name=品牌名称不能为空!, logo=logo不能为空!, logo=logo不能为空!, firstLetter=检索首字母不能为空!}at henu.soft.xiaosi.product.util.ValidateUtil.beanValidate(ValidateUtil.java:26)at henu.soft.xiaosi.product.util.ValidateUtil.main(ValidateUtil.java:32)Process finished with exit code 1
4.解决方法升级hibernate-validator依赖的版本
<!-- JSR303校验--><!-- <dependency>--><!-- <groupId>jakarta.validation</groupId>--><!-- <artifactId>jakarta.validation-api</artifactId>--><!-- <version>3.0.0</version>--><!-- </dependency>--><!-- <dependency>--><!-- <groupId>org.hibernate</groupId>--><!-- <artifactId>hibernate-validator</artifactId>--><!-- <version>5.2.4.Final</version>--><!-- </dependency>--> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>7.0.1.Final</version> </dependency>