1

在我的 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>

我怎样才能做到这一点?

4

2 回答 2

0

我按照此处提供的示例设法使其工作:https ://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/jaxrs/jaxrs-deltaspike-data

我做了以下动作:

1/ 删除beans.xml中的替代

2/在包含globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStrategysrc/main/resources/META-INF中添加apache-deltaspike.properties

于 2018-02-01T20:40:27.440 回答
0

Deltaspike 给出了更多的解释:

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

如果 Weld 的某些版本 - 包括 JBoss EAP/Wildfly 和 Websphere Liberty Profile 的几个版本 - 或 BDA 模式下的 OpenWebBeans - 这不是默认版本,您必须将其配置为全局替代方案,而不是 bean 中的替代方案。 xml

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

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

于 2018-02-11T02:23:17.790 回答