已编辑(我正在简化,因为我原来的问题太复杂了):
在 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>
看雄猫哭泣
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 提供程序而不会出现类加载器错误?