Deltaspike TransactionStrategy 替代模糊依赖项
Deltaspike TransactionStrategy Alternative Ambiguous dependencies
我正在 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 选项默认处于激活状态。因为当我删除全局替代定义时,我可以看到 deltaspike-data 模块使用 BeanManagedUserTransactionStrategy.
依赖版本:
- 焊接-se-着色:3.0.6.Final
- deltaspike:1.9.3
关于如何绕过它的任何想法?我需要使用 ResourceLocalTransactionStrategy.
我正在使用变通方法:从 beans 扫描中排除 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。
我正在 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 选项默认处于激活状态。因为当我删除全局替代定义时,我可以看到 deltaspike-data 模块使用 BeanManagedUserTransactionStrategy.
依赖版本:
- 焊接-se-着色:3.0.6.Final
- deltaspike:1.9.3
关于如何绕过它的任何想法?我需要使用 ResourceLocalTransactionStrategy.
我正在使用变通方法:从 beans 扫描中排除 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。