我按照文档(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;
似乎第一次注射有效,第二次注射失败。有想法吗?
答案 0 :(得分:0)
我终于找到了。
愚蠢的IDE从Spring框架自动导入了Qualifier类
import org.springframework.beans.factory.annotation.Qualifier;
认为正确的方法是
import javax.inject.Qualifier;