gpt4 book ai didi

java - org.jboss.weld.exceptions.DeploymentException WELD-001409 : Ambiguous dependencies for type X with qualifiers @Default

转载 作者:行者123 更新时间:2023-12-02 05:21:50 27 4
gpt4 key购买 nike

我按照文档(https://docs.jboss.org/weld/reference/latest/en-US/html/injection.html)创建限定符,现在我在wildfly-10.1.0.Final中遇到部署错误,我在互联网上红色了很多类似的问题,但仍然没有任何线索。该代码可以编译,并且注入(inject)对于其他类也可以很好地工作。

错误如下:

"{
\"WFLYCTL0080: Failed services\" => {\"jboss.deployment.unit.\\\"test.war\\\".WeldStartService\" => \"org.jboss.msc.service.StartException in service jboss.deployment.unit.\\\"test.war\\\".WeldStartService: Failed to start service
Caused by: org.jboss.weld.exceptions.DeploymentException: Exception List with 2 exceptions:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type MessageSender with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject @B private test.AccessService.messageSenderB
at test.AccessService.MessageSenderB(AccessService.java:0)
Possible dependencies:
- Managed Bean [class test.messagesender.impl.MessageSenderBImpl] with qualifiers [@Any @Default],
- Managed Bean [class test.messagesender.impl.MessageSenderAImpl] with qualifiers [@Any @Default]

以下是类(class):

@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;

似乎第一次注入(inject)有效,第二次注入(inject)失败。有什么想法吗?

最佳答案

终于找到了。

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

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

认为正确使用的是

import javax.inject.Qualifier;

关于java - org.jboss.weld.exceptions.DeploymentException WELD-001409 : Ambiguous dependencies for type X with qualifiers @Default,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56256024/

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