我正在使用Global Alternatives配置在apache-deltaspike.properties中定义TransactionStrategy:
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替代方案。原因当我删除Global替代定义时,我可以看到deltaspike-data模块使用BeanManagedUserTransactionStrategy。
依赖版本:
焊缝阴影:3.0.6。最终
deltaspike:1.9.3
关于如何解决它的任何想法?我需要使用ResourceLocalTransactionStrategy。
最佳答案
我正在使用一种解决方法:从bean扫描中排除BeanManagedUserTransactionStrategy。
我正在使用WELD特定的XML模式在beans.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。