【问题标题】:Spring Boot 2.0.4 and WAS Liberty transaction 18.0.0.2 Transaction manager issueSpring Boot 2.0.4 和 WAS Liberty 事务 18.0.0.2 事务管理器问题
【发布时间】:2019-01-29 13:47:40
【问题描述】:

我是 WAS Liberty 的新手,正在尝试部署 Spring Boot 应用程序。 服务器在启动时抛出异常。

[AVERTISSEMENT] 上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/boot/autoconfigure/orm/ 中定义的名称为“entityManagerFactory”的 bean 时出错jpa/HibernateJpaConfiguration.class]:init 方法调用失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory;嵌套异常是 java.lang.UnsupportedOperationException

问题在于 Hibernate 正在尝试使用错误的事务管理器类调用挂起: 原因:org.hibernate.engine.transaction.jta.platform.internal 处的 java.lang.UnsupportedOperationException。WebSphereExtendedJtaPlatform$TransactionManagerAdapter.suspend(WebSphereExtendedJtaPlatform.java:131)

这个类是由 Spring Boot 在 HibernateJpaConfiguration 类中配置的,它不包括正确的事务管理器:

私有静态最终字符串[] WEBSPHERE_JTA_PLATFORM_CLASSES = { "org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform", "org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" };

当我将类更改为 org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform 时,应用程序启动。这是配置问题还是 Spring Boot 不支持 WAS Liberty。

感谢您的帮助。

【问题讨论】:

标签: hibernate spring-boot websphere-liberty open-liberty


【解决方案1】:

根据此问题,WebSphereLibertyJtaPlatform 在 5.2.13 和 5.3.Beta2 版本中被引入 Hibernate:https://hibernate.atlassian.net/browse/HHH-11571

如果您使用的 Hibernate 版本包含 WebSphereLibertyJtaPlatform 并且未显式设置 JTA 平台类属性,则将自动检测和使用 Liberty 平台。

【讨论】:

    【解决方案2】:

    据我了解,Spring Boot 2.0.4 及其默认的 Hibernate 版本 (5.2.17) 支持 Liberty。然而,问题在于,如 Spring Boot issue #8926 中所述,Spring Boot 2.0.4 覆盖了 Websphere Liberty JTA 实现,否则 Hibernate 会正确设置。

    由于各种原因,我坚持使用 Liberty 16.0.0.4 和 Spring Boot 2.0.4,需要找到一种方法来设置正确的 Websphere Liberty JTA 实现。我最终使用 HibernatePropertiesCustomizer bean 覆盖了 hibernate.transaction.jta.platform 属性,就像这样

    @Bean
    public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
        return hibernateProperties ->
                hibernateProperties.put("hibernate.transaction.jta.platform",
                        "org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform");
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-29
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 2011-11-16
      • 1970-01-01
      • 2017-12-23
      • 2015-04-24
      • 1970-01-01
      相关资源
      最近更新 更多