Spring Boot 2.0.4和WAS Liberty事务18.0.0.2事务管理器问题

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

我是WAS Liberty的新手并试图部署一个spring boot应用程序。服务器在启动时抛出异常。

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

问题是Hibernate试图用错误的事务管理器类调用挂起:引起:org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform上的java.lang.UnsupportedOperationException $ TransactionManagerAdapter.suspend(WebSphereExtendedJtaPlatform.java) :131)

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

private static final String [] 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时,应用程序启动。这是配置问题还是不支持WAS Liberty的spring boot。

谢谢你的帮助。

hibernate spring-boot websphere-liberty open-liberty
2个回答
1
投票

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

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


0
投票

据我所知,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实现。我最终使用像这样的hibernate.transaction.jta.platform bean来覆盖HibernatePropertiesCustomizer属性

@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
    return hibernateProperties ->
            hibernateProperties.put("hibernate.transaction.jta.platform",
                    "org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform");
}
© www.soinside.com 2019 - 2024. All rights reserved.