代码之家  ›  专栏  ›  技术社区  ›  Gabriel

Liferay JPA ClassLoader错误

  •  0
  • Gabriel  · 技术社区  · 13 年前

    编辑(我正在简化,因为我最初的问题太复杂了):

    在Liferay 6.1.20中创建portlet插件

    在portlet的web.xml中添加一个spring上下文加载程序

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    

    在应用程序上下文中添加EntityManagerFactory的实例

    <bean id="localEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="WEB-INF/classes/META-INF/persistence.xml" />
    </bean>
    

    确保在您的持久性定义中引用了JPA实现

    <persistence-unit name="casd" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <properties>
            <property name="eclipselink.weaving" value="false" />
        </properties>
    </persistence-unit>
    

    看着Tomcat哭

    java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "org.eclipse.persistence.jpa.PersistenceProvider.getProviderUtil()Ljavax/persistence/spi/ProviderUtil;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/eclipse/persistence/jpa/PersistenceProvider, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for interface javax/persistence/spi/PersistenceProvider have different Class objects for the type javax/persistence/spi/ProviderUtil used in the signature
    

    玩hibernate3.jar、eclipselink.jar、persistence.jar直到筋疲力尽,然后意识到Liferay在对你咧嘴笑。

    你怎么能抹去Liferay脸上那令人恼火的笑容呢? 换句话说,

    如何在不出现类加载器错误的情况下,在liferay 6.1.20中的portlet插件中的spring上下文中实例化JPA提供程序?

    1 回复  |  直到 13 年前
        1
  •  0
  •   Gabriel    13 年前

    好的。我设法“解决”了将ecliseplink.jar从/ROOT/WEB-INF/lib移动到{tomcat}/lib/ext的问题

    我不喜欢把它作为一种解决方案,不得不处理ext,但这是一种要么接受要么放弃的情况。