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

时间:2018-08-23 08:31:55

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

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

[AVERTISSEMENT]上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建类路径资源[org / springframework / boot / autoconfigure / orm /中定义的名称为'entityManagerFactory'的bean时出错[jpa / HibernateJpaConfiguration.class]:初始化方法的调用失败;嵌套的异常是javax.persistence.PersistenceException:[PersistenceUnit:默认]无法构建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。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

WebSphereLibertyJtaPlatform是从Hibernate 5.2.13和5.3.Beta2版本开始引入的,其依据是以下问题:https://hibernate.atlassian.net/browse/HHH-11571

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

答案 1 :(得分: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");
}