在我的wildfly群应用程序中,我想将deltaspike与数据模块JPA和JTA一起使用。
我已经定义了bean.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),而不是我的bean.xml中定义的替代策略(EnvironmentAwareTransactionStrategy)。
文件bean.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>
你可以看看吗?
谢谢。
达米安
最佳答案
我设法通过遵循此处提供的示例使其起作用:https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/jaxrs/jaxrs-deltaspike-data
我已采取以下措施:
1 /在bean.xml中删除了替代方案
2 /在src / main / resources / META-INF中添加apache-deltaspike.properties,其中包含globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy = org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStrategy
但是,我有点好奇。有人可以向我解释为什么替代方法不起作用吗?是因为deltaspike jpa位于另一个jar中吗?类路径问题?
关于java - Deltaspike替代TransactionStrategy问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48571081/