×
文章路径: 开发运维环境

hibernate-validator在windows服务器下和weblogic冲突

发表于1年前(Sep 14, 2016 5:17:08 PM)  阅读 517  评论 0

分类: 开发运维环境

标签: hibernate-validator和weglogic冲突 traversableResolver

1、weblogic错误日志

ServletContext@18607596[app:website module:website path:/website spec-version:2.5]] Root cause of ServletException.
java.lang.AbstractMethodError
	at javax.persistence.Persistence$1.isLoaded(Persistence.java:111)
	at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:47)
	at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:128)
	at org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation.isReachable(CachingTraversableResolverForSingleValidation.java:36)
	at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1588)
	at org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1573)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:611)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:582)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForNonDefaultGroup(ValidatorImpl.java:542)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:456)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:206)
	at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:207)

weblogic版本为10.3.6,服务器操作系统为windows server2003,win7报同样错误,linux版本不报错。

2、错误原因

具体怎么找到错误原因的不说了,最终确认是因为项目中的hibernate-validator库和weblogic冲突导致的。hibernate-validator版本为5.2.4.Final,尝试过升级或降级hibernate-validator版本均失败,hibernate使用的是4.3.8。

3、解决办法

网上找到的解决办法,原spring配置文件中validator的配置项为:

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">  
	    <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
	    <property name="validationMessageSource" ref="messageSource"/>  
	</bean>

现增加traversableResolver属性配置:

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">  
	    <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>  
	    <property name="validationMessageSource" ref="messageSource"/>  
	    <property name="traversableResolver">
			<bean class="
XXX.ExtTraversableResolver"></bean>
		</property>
	</bean>

ExtTraversableResolver的实现为:

import java.lang.annotation.ElementType;

import javax.validation.Path;
import javax.validation.Path.Node;
import javax.validation.TraversableResolver;

public class ExtTraversableResolver implements TraversableResolver {

	@Override
	public boolean isReachable(Object traversableObject, Node traversableProperty, Class<?> rootBeanType,
			Path pathToTraversableObject, ElementType elementType) {
		return true;
	}

	@Override
	public boolean isCascadable(Object traversableObject, Node traversableProperty, Class<?> rootBeanType,
			Path pathToTraversableObject, ElementType elementType) {
		return true;
	}

}

发表评论