我是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.
我的代码如下:
Customer.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作为外部库。谁在这里谁可以帮助我?谢谢大家。
您的Customer类必须由CDI作为bean发现。为此你有两个选择:
原文链接:https://www.f2er.com/javaschema/282074.html>把bean defining annotation放在上面。因为@Model是一个刻板印象,所以它就是这样做的原因。像@Named这样的限定符不是定义注释的bean,因为它不起作用
>通过在jar中添加beans.xml文件,将bean discovery mode in your bean archive从默认的“annotated”更改为“all”。