【发布时间】:2015-04-05 19:25:59
【问题描述】:
我是 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;
}
registerController.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 作为外部库。这里有人可以帮助我吗?提前谢谢大家。
【问题讨论】:
-
我认为您的问题是客户不是@Named。
-
CDI 是否知道
Customer类(例如托管 bean 或(本地)EJB)? -
大家好,这真的很有帮助,谢谢!!实际上,用
注释类“customer”是行不通的,但是用 就可以了。但是为什么...? -
在下面为您提供正确且记录在案的答案。
-
由于这是本主题中访问量最大的问题,因此我在此处添加 2 美分。 如果您碰巧在多模块 Maven 环境中工作,请确保在添加下面提到的任何 bean 定义注释后编译包含您的 bean 的模块
标签: jsf jakarta-ee dependency-injection cdi managed-bean