gpt4 book ai didi

jsf - WELD-001408 : Unsatisfied dependencies for type Customer with qualifiers @Default

转载 作者:行者123 更新时间:2023-12-03 07:49:19 24 4
gpt4 key购买 nike

我是 Java EE 新手。我想测试JSF,因此做了一个简单的程序,但无法部署它。我收到以下错误消息:

cannot Deploy onlineshop-war
deploy is failing=Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private de.java2enterprise.onlineshop.RegisterController.customer
at de.java2enterprise.onlineshop.RegisterController.customer(RegisterController.java:0)
. Please see server.log for more details.

我的代码如下:
客户.java:
package de.java2enterprise.onlineshop.model;

public class Customer {
private String email;
private String password;
}

注册 Controller .java:
package de.java2enterprise.onlineshop;

import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.inject.Inject;
import de.java2enterprise.onlineshop.model.*;

@Named
@RequestScoped
public class RegisterController {

private static final long serialVersionUID = 1L;

@Inject
private Customer customer;

public Customer getCustomer() {
return customer;
}

public void setCustomer(Customer customer) {
this.customer = customer;
}

public String persist() {
return "/index.xhtml";
}
}

为了编译它,我必须包含 cdi-api.jar 作为外部库。这里有人可以帮助我吗?谢谢大家。

最佳答案

您的 Customer CDI 必须将类作为 bean 发现。为此,您有两个选择:

  • 放一个 bean defining annotation在上面。如 @Model是一种刻板印象,这就是它起作用的原因。像 @Named 这样的限定符不是定义注释的 bean,为什么它不起作用
  • 更改 bean discovery mode in your bean archive通过添加 beans.xml 从默认的“注释”到“全部”文件在你的 jar 中。

  • 请记住,@Named 只有一种用法:将您的 bean 暴露给 UI。其他用法用于不良实践或与遗留框架的兼容性。

    关于jsf - WELD-001408 : Unsatisfied dependencies for type Customer with qualifiers @Default,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28352461/

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