org.jboss.weld.exceptions.DeploymentException WELD-001409:带有限定符@Default的X类型的依存关系

时间:2019-05-22 11:39:54

标签: java jboss cdi qualifiers

我按照文档(https://docs.jboss.org/weld/reference/latest/en-US/html/injection.html)创建了限定词,现在在wildfly-10.1.0中遇到了部署错误。最后,我在互联网上重复了很多类似的问题,但仍然毫无头绪。 该代码可以编译,并且注入对于其他类也能很好地工作。

这是错误:

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Documented
public @interface A{}

以下是课程:

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Documented
public @interface B{}
public interface MessageSender {}
@Singleton
@A
public class MessageSenderAImpl implements MessageSender {}
@Singleton
@B
public class MessageSenderBImpl implements MessageSender {}
@Singleton
public class AccessService {
    @Inject
    @A
    private MessageSender messageSenderA;

    @Inject
    @B
    private MessageSender messageSenderB;
// create categories
final short A = 0x0001;  // 0000000000000001 in binary
final short B = 0x0002; // 0000000000000010 in binary
final short C = 0x0004; // 0000000000000100 in binary

// create masks
final short AM = 0x0006 // 0000000000000110 in binary
final short BM = 0x0006 // 0000000000000110 in binary
final short CM = 0x0001 // 0000000000000001 in binary

// apply masks and categories to fixtures
FixtureDef ADef = new FixtureDef();
ADef.filter.categoryBits = A;
ADef.filter.maskBits = AM;

似乎第一次注射有效,第二次注射失败。有想法吗?

1 个答案:

答案 0 :(得分:0)

我终于找到了。

愚蠢的IDE从Spring框架自动导入了Qualifier类

import org.springframework.beans.factory.annotation.Qualifier;

认为正确的方法是

import javax.inject.Qualifier;