Jakarta ee 同一bean中的两个生产者会导致歧义错误

Jakarta ee 同一bean中的两个生产者会导致歧义错误,jakarta-ee,cdi,Jakarta Ee,Cdi,我正在学习JavaEE中的CDI和不同的注释。我创建了一个。我使用同一个托管bean生成两个问候字符串。非正式的和正式的。我发现以下错误: SEVERE: Exception while loading the app : CDI deployment failure:WELD-001409 Ambiguous dependencies for type [String] with qualifiers [@Formal] at injection point [[BackedAnnotat

我正在学习JavaEE中的CDI和不同的注释。我创建了一个。我使用同一个托管bean生成两个问候字符串。非正式的和正式的。我发现以下错误:

SEVERE:   Exception while loading the app : CDI deployment failure:WELD-001409 Ambiguous dependencies for type [String] with qualifiers [@Formal] at injection point [[BackedAnnotatedField] @Inject @Formal mypackage.HelloServlet.formalMessage]. Possible dependencies [[Producer Method [String] with qualifiers [@Formal @Any] declared as [[BackedAnnotatedMethod] @Produces @Formal public mypackage.ProduceFormalGreeting.GetFormalGreeting()], Producer Method [String] with qualifiers [@Formal @Any] declared as [[BackedAnnotatedMethod] @Produces @Formal public mypackage.ProduceGreeting.GetFormalGreeting()]]]
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [String] with qualifiers [@Formal] at injection point [[BackedAnnotatedField] @Inject @Formal mypackage.HelloServlet.formalMessage]. Possible dependencies [[Producer Method [String] with qualifiers [@Formal @Any] declared as [[BackedAnnotatedMethod] @Produces @Formal public mypackage.ProduceFormalGreeting.GetFormalGreeting()], Producer Method [String] with qualifiers [@Formal @Any] declared as [[BackedAnnotatedMethod] @Produces @Formal public mypackage.ProduceGreeting.GetFormalGreeting()]]]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:406)
我不知道为什么第一个函数用正式注释,第二个用非正式注释时会有歧义。当我删除其中一个函数或将其移动到另一个bean类时,错误就会消失。多谢各位

public class ProduceGreeting {

    @Produces
    @Formal
    public String GetFormalGreeting(){
        return "Good morning !";
    }

    @Produces
    @InFormal
    public String GetInFormalGreeting(){
        return "Hi there !";
    }
}
调用ProduceGreeting类的Servlet:

@Inject
@Formal
String formalMessage;

@Inject
@InFormal
String informalMessage;
...
...

 out.println("<h2> Formal Greeting: " + formalMessage + "</h2>");
 out.println("<h2> Informal Greeting: " + informalMessage + "</h2>");

错误消息显示您有一个

mypackage.ProduceFormalGreeting.GetFormalGreeting()
方法和a

mypackage.ProduceGreeting.GetFormalGreeting()

还有。我想您需要在
target
目录中进行清理,以删除旧类(它可能在开发过程中被重命名)。(代码很好,它适用于我的Java SE。)

谢谢@palacsint。我必须手动删除目标文件夹并生成。基于netbeans的清理和构建由于某些原因无法工作。
mypackage.ProduceGreeting.GetFormalGreeting()