无法在websphere自由配置文件中创建EntityManagerFactory

问题描述 投票:1回答:2

问题描述:

我正在尝试将Web应用程序从Websphere 8.5.5迁移到我的本地Eclipse环境下的Websphere Liberty Profile(WLP 16.0.0.3)。该应用程序在Websphere中运行良好,但是当在WLP中启动时,我得到以下异常:

创建名为'entityManagerFactory'的bean时出错:FactoryBean对象的后处理失败;嵌套异常是java.lang.NoClassDefFoundError:org.apache.openjpa.persistence.query.QueryBuilder

我希望QueryBuilder类存在于Liberty运行时提供的opnJPA实现中,但由于某种原因未正确加载。任何帮助将不胜感激。

关于jpa配置的几个细节:

  • WLP jpa级别:jpa-2.0
  • 春季版:3.1.4.RELEASE
  • EntityManagerFactory bean:class =“org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean”
  • jpaVendorAdapter:class =“org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter”
  • 事务管理器:class =“org.springframework.orm.jpa.JpaTransactionManager”
spring jpa websphere-liberty
2个回答
1
投票

默认情况下,jpa-2.0功能仅向应用程序公开规范标准JPA包。它没有公开JPA特定于实现特定的类的开箱即用。

在您的情况下,由于您需要将Liberty的OpenJPA类暴露给您的应用程序(以及应用程序内的库,如Spring / Hibernate),您可以使用Liberty的“api type visibilty”机制来选择使用它。

我猜你在server.xml中配置了这样的应用程序:

<application location="myApp.war"/>

要允许您的应用程序查看第三方(例如OpenJPA)类,您可以执行以下操作:

<application location="myApp.war">
  <!-- spec, ibm-api, and stable are enabled by default. -->
  <!-- Add third-party to get access to OpenJPA classes from your application -->
  <classloader apiTypeVisibility="spec, ibm-api, stable, third-party"/>
</application>

官方Liberty文档:Accessing third-party APIs

你可能想知道:

为什么Liberty没有默认提供third-party类,比如OpenJPA?

这是因为当所有事情保持不变并且您只是升级到更新的Liberty版本时,Liberty会保留零迁移。零迁移本质上意味着“在升级时,您不必更改任何应用程序或配置”。第三方类不受Liberty的直接控制,并且可能会破坏API更改,从而打破零迁移。因此,Liberty默认情况下仅公开官方/标准API,例如JavaEE和MicroProfile API。


1
投票

默认情况下,Liberty会从应用程序中隐藏非API类。被认为是API的东西是Java EE,MicroProfile和其他一些东西。您可以通过配置打开第三方开源API。

配置如下:

<webApplication location="myapp.war">
  <classLoader apiTypeVisibility="+third-party" />
</webApplication>

鉴于您未提供服务器配置示例或异常的堆栈跟踪,我不知道这是否能解决您的问题,但这是基于有限信息的最佳建议。

此配置可能无法在16.0.0.3上运行。可能最近添加了+第三方支持(如果它不替代spec,ibm-api,api,stable,third-party将起作用,但更加冗长且不太可用)。我强烈建议升级到更新的版本,因为16.0.0.3不再提供功能或安全修复程序。最新版本是19.0.0.3。

© www.soinside.com 2019 - 2024. All rights reserved.