javax.validation.ValidationException:无法找到默认提供程序
作者:互联网
我向托管bean添加了一些验证(@NotNull),突然出现此错误.任何想法可能会导致它吗?该应用程序在Apache Tomcat 7中运行.
javax.validation.ValidationException: Unable to find a default provider
javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)
javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
javax.faces.validator.BeanValidator.validate(BeanValidator.java:271)
javax.faces.component.UIInput.validateValue(UIInput.java:1127)
javax.faces.component.UIInput.validate(UIInput.java:941)
javax.faces.component.UIInput.executeValidate(UIInput.java:1189)
javax.faces.component.UIInput.processValidators(UIInput.java:691)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
javax.faces.component.UIForm.processValidators(UIForm.java:243)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1180)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
解决方法:
在应用程序服务器中,您的应用程序的类路径中似乎没有JSR 303 Bean验证提供程序.如果使用的是Glassfish,最好在$GLASSFISH_INSTALL_ROOT / glassfish / modules目录中验证bean-validator.jar的存在. Glassfish 3.1使用此JAR(包含Hibernate Validator实现)充当默认的JSR 303 Bean验证提供程序.我怀疑您使用的是Glassfish的较旧版本,或不包含Bean验证提供程序的其他应用程序服务器.
如果必须在类路径中包括Bean验证提供程序,请考虑阅读ValidationProviderResolver
interface的Java API文档,该文档指出:
Bean Validation providers are identified by the presence of
META-INF/services/javax.validation.spi.ValidationProvider files
following the Service Provider pattern described 07001Each META-INF/services/javax.validation.spi.ValidationProvider file
contains the list of ValidationProvider implementations each of them
representing a provider.
因此,如果确实在类路径中包括Bean验证提供程序,则必须确保在类路径中存在META-INF / services / javax.validation.spi.ValidationProvider文件,并且该文件还包含Bean的名称.验证提供者.下面列出了Glassfish提供的内容的内容,它们指向Hibernate Bean Validator类:
org.hibernate.validator.HibernateValidator
标签:java,tomcat,jsf,bean-validation 来源: https://codeday.me/bug/20191012/1897424.html