无法在 websphere 自由配置文件中创建 EntityManagerFactory
EntityManagerFactory cannot be created in websphere liberty profile
问题描述:
我正在尝试在本地 Eclipse 环境下将 Web 应用程序从 Websphere 8.5.5 迁移到 Websphere Liberty Profile (WLP 16.0.0.3)。该应用程序在 Websphere 中运行良好,但在 WLP 中启动时出现以下异常:
创建名为 'entityManagerFactory' 的 bean 时出错:Post- 处理 FactoryBean 的对象失败;嵌套异常是 java.lang.NoClassDefFoundError: org.apache.openjpa.persistence.query.QueryBuilder
我希望 QueryBuilder class 出现在 Liberty 运行时提供的 opnJPA 实现中,但由于某种原因未正确加载。
任何帮助将不胜感激。
关于 jpa 配置的一些细节:
WLP jpa级别:jpa-2.0
Spring版本: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"
默认情况下,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>
自由官方文档:Accessing third-party APIs
您可能想知道:
Why does Liberty not make third-party
classes, such as OpenJPA, available by default?
这是因为当所有事情都保持不变并且您只需升级到较新的 Liberty 版本时,Liberty 保证零迁移。零迁移本质上意味着 "you won't have to change any of your app or config when you upgrade"。第三方 类 不受 Liberty 的直接控制,可能会做出重大 API 更改,从而破坏零迁移。为此,Liberty 默认只公开了 official/standard API 类,例如 JavaEE 和 MicroProfile APIs.
Liberty 默认对应用程序隐藏非API 类。 API 考虑的事情是 Java EE、MicroProfile 和其他一些东西。可以通过配置开放给第三方开源api。
这样的配置:
<webApplication location="myapp.war">
<classLoader apiTypeVisibility="+third-party" />
</webApplication>
鉴于您没有提供服务器配置示例或异常堆栈跟踪,我不知道这是否能解决您的问题,但这是基于有限信息的最佳建议。
此配置可能不适用于 16.0.0.3。 +third-party 支持可能是最近添加的(如果它没有替代 spec,ibm-api,api,stable,third-party
会起作用,但更冗长且不太可用)。我强烈建议升级到更新的版本,因为 16.0.0.3 不再提供功能或安全修复。最新版本是 19.0.0.3。
问题描述:
我正在尝试在本地 Eclipse 环境下将 Web 应用程序从 Websphere 8.5.5 迁移到 Websphere Liberty Profile (WLP 16.0.0.3)。该应用程序在 Websphere 中运行良好,但在 WLP 中启动时出现以下异常:
创建名为 'entityManagerFactory' 的 bean 时出错:Post- 处理 FactoryBean 的对象失败;嵌套异常是 java.lang.NoClassDefFoundError: org.apache.openjpa.persistence.query.QueryBuilder
我希望 QueryBuilder class 出现在 Liberty 运行时提供的 opnJPA 实现中,但由于某种原因未正确加载。 任何帮助将不胜感激。
关于 jpa 配置的一些细节:
WLP jpa级别:jpa-2.0
Spring版本: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"
默认情况下,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>
自由官方文档:Accessing third-party APIs
您可能想知道:
Why does Liberty not make
third-party
classes, such as OpenJPA, available by default?
这是因为当所有事情都保持不变并且您只需升级到较新的 Liberty 版本时,Liberty 保证零迁移。零迁移本质上意味着 "you won't have to change any of your app or config when you upgrade"。第三方 类 不受 Liberty 的直接控制,可能会做出重大 API 更改,从而破坏零迁移。为此,Liberty 默认只公开了 official/standard API 类,例如 JavaEE 和 MicroProfile APIs.
Liberty 默认对应用程序隐藏非API 类。 API 考虑的事情是 Java EE、MicroProfile 和其他一些东西。可以通过配置开放给第三方开源api。
这样的配置:
<webApplication location="myapp.war">
<classLoader apiTypeVisibility="+third-party" />
</webApplication>
鉴于您没有提供服务器配置示例或异常堆栈跟踪,我不知道这是否能解决您的问题,但这是基于有限信息的最佳建议。
此配置可能不适用于 16.0.0.3。 +third-party 支持可能是最近添加的(如果它没有替代 spec,ibm-api,api,stable,third-party
会起作用,但更冗长且不太可用)。我强烈建议升级到更新的版本,因为 16.0.0.3 不再提供功能或安全修复。最新版本是 19.0.0.3。