javax.validation.ValidationException:调用TraversableResolver.isReachable()引发异常

时间:2015-10-06 15:25:14

标签: spring

我的应用程序在Exception下面,对于Spring中的bean验证,我使用的是Spring4.0.2版本。

我正在使用weblogic11g应用程序服务器

javax.validation.ValidationException:调用TraversableResolver.isReachable()引发异常         at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:773)         at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:331)         at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)         at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)         at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)         截断。查看日志文件以获取完整的堆栈跟踪 引发者:javax.persistence.PersistenceException:无法从META-INF / services加载提供程序         at javax.persistence.spi.PersistenceProviderResolverHolder $ DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:121)         在javax.persistence.Persistence $ PersistenceUtilImpl.isLoaded(Persistence.java:278)         在org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)         at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:112)         at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)         截断。查看日志文件以获取完整的堆栈跟踪 引发者:java.lang.ClassCastException:org.apache.openjpa.persistence.PersistenceProviderImpl无法强制转换为javax.persistence.spi.PersistenceProvider         at javax.persistence.spi.PersistenceProviderResolverHolder $ DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:110)         在javax.persistence.Persistence $ PersistenceUtilImpl.isLoaded(Persistence.java:278)         在org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)         at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:112)         at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)         截断。请参阅日志文件以获取完整的堆栈跟踪

这是我的POJO课程

import java.util.Date;

import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;


public class TestVO extends BaseVO {

        private static final long serialVersionUID = 1L;

        @Length(max=18)
        @NotNull
        @NotEmpty
        @Pattern(regexp = "[a-zA-Z0-9]*")
        private String Id;

                public String getId() {
                return Id;
        }

        public void setId(String Id) {
                this.Id = Id;
        }


}

这是我的验证员类

import javax.validation.ConstraintViolation;
import javax.validation.Validator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DataValidator {

        @Autowired(required = true)
        private Validator validator;

        public Set<ConstraintViolation<Object>>  validate(Object tvo) {
                return this.validator.validate(tvo);
        }
}

这是我的控制器类,我正在尝试验证我的POJO

@Autowired
private DataValidator dValidator;

TestVO testVO = testBO.getTest(id);
Set<ConstraintViolation<Object>> violations = this.dValidator.validate(testVO);

我已使用以下验证器

更新了application-context.xml
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

I have below Jar's in place in my WEB-INF/lib

hibernate-validator-4.0.1.GA.jar
validation-api-1.0.0.GA.jar
j2ee.jar
javax.persistence_1.0.0.0_1-0-2.jar
commons-logging-1.1.1.jar

任何帮助都非常感谢。

2 个答案:

答案 0 :(得分:1)

此问题通常发生在加载同名类但来自不同类加载器的类冲突中。我建议你检查任何重复的持久性jar文件(在你的情况下是javax.persistence_1.0.0.0_1-0-2.jar)并删除它们(它们)

答案 1 :(得分:0)

如果您正在使用某些Hibernate字节码增强配置,您也可能会遇到此异常。见https://hibernate.atlassian.net/browse/HHH-11294