Weblogic 10.3.6上的Spring-MVC-4 + JPA 2 + Hibernate Validation 5.0.2

时间:2014-02-07 01:36:40

标签: hibernate spring-mvc jpa weblogic11g

经过网上多次搜索,我还没有找到解决方案。 我在WebLogic 10.3.6上使用JPA 2。 在tomcat上一切运作良好:

@RequestMapping(value="/createUser", method = RequestMethod.POST)
public String create(@Valid Utente utente, BindingResult result)


但是当我部署到WebLogic时,我得到了这个例外:

java.lang.AbstractMethodError: org.apache.openjpa.persistence.PersistenceProviderImpl.getProviderUtil()Ljavax/persistence/spi/ProviderUtil;
at javax.persistence.Persistence$PersistenceUtilImpl.isLoaded(Unknown Source) ~[javax.persistence_1.1.0.0_2-0.jar:2.0.3]
at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:56) ~[hibernate-validator-5.0.2.Final.jar:5.0.2.Final]


这是pom.xml:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.0.0.RELEASE</version>
</dependency>
...
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.0.2.Final</version>
</dependency>

提前致谢

2 个答案:

答案 0 :(得分:1)

通过输入validation.xml解决:

<?xml version="1.0" encoding="UTF-8"?>
<validation-config
    xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.1.xsd"
    version="1.1">

    <traversable-resolver>CustomTraversableResolver</traversable-resolver>

</validation-config>

并实施:

public class CustomTraversableResolver 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;
    }
}

答案 1 :(得分:0)

here一样,@ MRS响应是一种解决方法,因为您应该知道这可能导致在验证具有未加载的其他实体的惰性引用的bean时从数据库加载大量实体

我建议编辑weblogic-application.xml以重载正确的jar:

<wls:prefer-application-packages>
    <wls:package-name>javax.persistence.*</wls:package-name>
    <wls:package-name>org.eclipse.persistence.*</wls:package-name>
</wls:prefer-application-packages>