gpt4 book ai didi

java - Deltaspike 替代 TransactionStrategy 问题

转载 作者:太空宇宙 更新时间:2023-11-04 10:44:25 26 4
gpt4 key购买 nike

在我的 Wildfly swarm 应用程序中,我想将 deltaspike 与数据模块、JPA 和 JTA 一起使用。

我已将 beans.xml 定义为使用 EnvironmentAwareTransactionStrategy 作为 TransactionStrategy

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
<alternatives>
<class>org.apache.deltaspike.jpa.impl.transaction.EnvironmentAwareTransactionStrategy</class>
</alternatives>

但是,当我运行我的应用程序时,会引发此异常:

at org.hibernate.jpa.spi.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:1333)
at org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.getTransaction(ResourceLocalTransactionStrategy.java:372)
at org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.rollbackAllTransactions(ResourceLocalTransactionStrategy.java:338)
at org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.execute(ResourceLocalTransactionStrategy.java:155)
at org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.executeInTransaction(TransactionalInterceptor.java:57)

CDI 使用默认的 TransactionStrategy (ResourceLocalTransactionStrategy),而不是我的 beans.xml 中定义的替代策略 (EnvironmentAwareTransactionStrategy)。

文件 beans.xml 位于 src/main/resources/META-INF 中,并且在我的 pom.xml

    <dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>datasources</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jpa</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-data-module-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-data-module-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-jpa-module-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-jpa-module-impl</artifactId>
<scope>runtime</scope>
</dependency>

我该怎么做?

最佳答案

Deltaspike 给出了更多使用说明:

https://deltaspike.apache.org/documentation/jpa.html

In case of some versions of Weld - including several versions of JBoss EAP/Wildfly and Websphere Liberty Profile - or OpenWebBeans in BDA mode - which is not the default one, you have to configure it as a global alternative instead of an alternative in beans.xml

https://deltaspike.apache.org/documentation/spi.html#GlobalAlternative

他们建议使用 apache-deltaspike.properties 作为解决方法。

关于java - Deltaspike 替代 TransactionStrategy 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48571081/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com