gpt4 book ai didi

java - org.jboss.weld.exceptions.UnsatisfiedResolutionException WELD-001334 类型 MyInterface 与限定符 @Any @MyAnnotation 的依赖关系不满足

转载 作者:行者123 更新时间:2023-12-02 10:10:04 24 4
gpt4 key购买 nike

我有一个 Java 8 项目和一个 JBoss 7.1.0GA 服务器。我有一个带有全局变量的批处理类

@EJB
public MyInterface delegate;

它在我的 ejb-jar.xml 中定义为 DelegateClass 的实例:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<module-name>moduleName</module-name>
<enterprise-beans>
<session>
<ejb-name>ejbName</ejb-name>
<business-remote>MyInterface</business-remote>
<ejb-class>DelegateClass</ejb-class>
<session-type>Stateless</session-type>
</session>
</enterprise-beans>

我有一些 MyInterface 的实现,因此在我的类 DelegateClass 中,我想包装 MyInterface 的实现并通过枚举常量设置它。代码如下:

@Stateless
@LocalBean
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DelegateClass implements MyInterface {

@Inject
@Any
protected Instance<MyInterface> instance;

protected MyInterface selectedImpl;

@PostConstruct
public void init() {
selectedImpl = instance.select(MyLiteralAnnotation.create(MyEnum.value)).get();
}

这是我的文字注释类的代码:

public class MyLiteralAnnotation extends AnnotationLiteral<MyAnnotation> implements MyAnnotation {

private final MyEnum value;

private MyLiteralAnnotation(MyEnum value) {
this.value = value;
}

@Override
public MyEnum getValue() {
return value;
}

public static MyLiteralAnnotation create(MyEnum value) {
return new MyLiteralAnnotation(value);
}

}

我创建的注释:

@Retention(RetentionPolicy.RUNTIME)

@Target({ TYPE, METHOD, FIELD, PARAMETER, CONSTRUCTOR })
@Qualifier
public @interface MyAnnotation {

MyEnum getValue();
}

以及我想从instance.select(...)获得的实现

@Stateless
@LocalBean
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@MyAnnotation(MyEnum.value)
public class MyInterfaceImpl implements MyInterface {
....
}

我在服务器上调试应用程序,但是当我尝试使用 instance.select(...) 实例化 selectImpl 字段时,出现异常:

org.jboss.weld.exceptions.UnsatisfiedResolutionException WELD-001334 Unsatisfied dependencies for type MyInterface with qualifiers @Any @MyAnnotation

有人可以帮我吗?

最佳答案

我解决了在委托(delegate)类定义上添加注释 @ApplicationScope 的问题。

关于java - org.jboss.weld.exceptions.UnsatisfiedResolutionException WELD-001334 类型 MyInterface 与限定符 @Any @MyAnnotation 的依赖关系不满足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55066730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com