0

我在apache-deltaspike.properties中定义TransactionStrategy,使用 Global Alternatives 配置:

globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy

我的beans.xml只有deltaspike-data模块拦截器:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       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">
    <interceptors>
        <class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
    </interceptors>
</beans>

但是我被下面的异常击中了,这对我来说没有任何意义:

WELD-001409: Ambiguous dependencies for type TransactionStrategy with qualifiers @Default
  at injection point [UnbackedAnnotatedField] @Inject private org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.transactionStrategy
  at org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.transactionStrategy(TransactionalInterceptor.java:0)
  Possible dependencies: 
  - Managed Bean [class org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy] with qualifiers [@Any @Default],
  - Managed Bean [class org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy] with qualifiers [@Any @Default]

显然,默认情况下会激活BeanManagedUserTransactionStrategy替代方案。因为当我删除全局替代定义时,我可以看到deltaspike-data模块使用BeanManagedUserTransactionStrategy

依赖版本:

  • 焊接阴影:3.0.6.Final
  • 增量峰值:1.9.3

关于如何绕过它的任何想法?我需要使用ResourceLocalTransactionStrategy

4

1 回答 1

0

我正在使用一种解决方法:从 bean 扫描中排除BeanManagedUserTransactionStrategy 。

我在beans.xml中使用WELD特定的 XML 模式执行此操作:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:weld="http://jboss.org/schema/weld/beans">
    <weld:scan>
        <weld:exclude name="org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy"/>
    </weld:scan>
    <interceptors>
        <class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
    </interceptors>
</beans>

通过这样做,我放弃了可移植性,这意味着这只适用于WELD

于 2020-04-26T11:36:57.120 回答